diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-05-20 09:52:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-05-20 09:52:49 +0300 |
commit | f606f588455ef6909b98a35839ee6eb0eda6516d (patch) | |
tree | 56226c3ae7bcf87995eda8a600dd9eb36bcabfec /source/blender/windowmanager/intern | |
parent | 3184460ff7f4f660a70ec7a18a3a882eb2de57f8 (diff) |
Cleanup: add wm_utils.c for generic functions
Diffstat (limited to 'source/blender/windowmanager/intern')
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 31 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_utils.c | 71 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_window.c | 12 |
3 files changed, 76 insertions, 38 deletions
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index fd193225a49..d91f30d6945 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -2855,7 +2855,7 @@ static void wm_block_file_close_cancel(bContext *C, void *arg_block, void *UNUSE static void wm_block_file_close_discard(bContext *C, void *arg_block, void *arg_data) { - wmGenericCallback *callback = wm_generic_callback_steal((wmGenericCallback *)arg_data); + wmGenericCallback *callback = WM_generic_callback_steal((wmGenericCallback *)arg_data); /* Close the popup before executing the callback. Otherwise * the popup might be closed by the callback, which will lead @@ -2864,12 +2864,12 @@ static void wm_block_file_close_discard(bContext *C, void *arg_block, void *arg_ UI_popup_block_close(C, win, arg_block); callback->exec(C, callback->user_data); - wm_generic_callback_free(callback); + WM_generic_callback_free(callback); } static void wm_block_file_close_save(bContext *C, void *arg_block, void *arg_data) { - wmGenericCallback *callback = wm_generic_callback_steal((wmGenericCallback *)arg_data); + wmGenericCallback *callback = WM_generic_callback_steal((wmGenericCallback *)arg_data); bool execute_callback = true; wmWindow *win = CTX_wm_window(C); @@ -2897,7 +2897,7 @@ static void wm_block_file_close_save(bContext *C, void *arg_block, void *arg_dat if (execute_callback) { callback->exec(C, callback->user_data); } - wm_generic_callback_free(callback); + WM_generic_callback_free(callback); } static void wm_block_file_close_cancel_button(uiBlock *block, wmGenericCallback *post_action) @@ -3039,7 +3039,7 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C, struct ARegi static void free_post_file_close_action(void *arg) { wmGenericCallback *action = (wmGenericCallback *)arg; - wm_generic_callback_free(action); + WM_generic_callback_free(action); } void wm_close_file_dialog(bContext *C, wmGenericCallback *post_action) @@ -3054,25 +3054,4 @@ bool wm_file_or_image_is_modified(const bContext *C) return !wm->file_saved || ED_image_should_save_modified(C); } -void wm_generic_callback_free(wmGenericCallback *callback) -{ - if (callback->free_user_data) { - callback->free_user_data(callback->user_data); - } - MEM_freeN(callback); -} - -static void do_nothing(bContext *UNUSED(C), void *UNUSED(user_data)) -{ -} - -wmGenericCallback *wm_generic_callback_steal(wmGenericCallback *callback) -{ - wmGenericCallback *new_callback = MEM_dupallocN(callback); - callback->exec = do_nothing; - callback->free_user_data = NULL; - callback->user_data = NULL; - return new_callback; -} - /** \} */ diff --git a/source/blender/windowmanager/intern/wm_utils.c b/source/blender/windowmanager/intern/wm_utils.c new file mode 100644 index 00000000000..c0ee1ec44db --- /dev/null +++ b/source/blender/windowmanager/intern/wm_utils.c @@ -0,0 +1,71 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup wm + * + * Generic helper utilies that aren't assosiated with a particular area. + */ + +#include "WM_types.h" +#include "WM_api.h" + +#include "MEM_guardedalloc.h" + +/* -------------------------------------------------------------------- */ +/** \name Generic Callback + * \{ */ + +void WM_generic_callback_free(wmGenericCallback *callback) +{ + if (callback->free_user_data) { + callback->free_user_data(callback->user_data); + } + MEM_freeN(callback); +} + +static void do_nothing(struct bContext *UNUSED(C), void *UNUSED(user_data)) +{ +} + +wmGenericCallback *WM_generic_callback_steal(wmGenericCallback *callback) +{ + wmGenericCallback *new_callback = MEM_dupallocN(callback); + callback->exec = do_nothing; + callback->free_user_data = NULL; + callback->user_data = NULL; + return new_callback; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Generic User Data + * \{ */ + +void WM_generic_user_data_free(wmGenericUserData *wm_userdata) +{ + if (wm_userdata->data && wm_userdata->use_free) { + if (wm_userdata->free_fn) { + wm_userdata->free_fn(wm_userdata->data); + } + else { + MEM_freeN(wm_userdata->data); + } + } +} + +/** \} */ diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 0f93a03da6b..7ae572e5685 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -2290,15 +2290,3 @@ void WM_opengl_context_release(void *context) BLI_assert(GPU_framebuffer_active_get() == NULL); GHOST_ReleaseOpenGLContext((GHOST_ContextHandle)context); } - -void WM_generic_user_data_free(wmGenericUserData *wm_userdata) -{ - if (wm_userdata->data && wm_userdata->use_free) { - if (wm_userdata->free_fn) { - wm_userdata->free_fn(wm_userdata->data); - } - else { - MEM_freeN(wm_userdata->data); - } - } -} |