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 | |
parent | 3184460ff7f4f660a70ec7a18a3a882eb2de57f8 (diff) |
Cleanup: add wm_utils.c for generic functions
-rw-r--r-- | source/blender/windowmanager/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 5 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_types.h | 6 | ||||
-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 | ||||
-rw-r--r-- | source/blender/windowmanager/wm_files.h | 11 |
7 files changed, 89 insertions, 48 deletions
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index 7e53c652ab5..64f506f03a8 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -74,6 +74,7 @@ set(SRC intern/wm_toolsystem.c intern/wm_tooltip.c intern/wm_uilist_type.c + intern/wm_utils.c intern/wm_window.c gizmo/intern/wm_gizmo.c gizmo/intern/wm_gizmo_group.c diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 346996285a4..bbdd5bc85bd 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -796,7 +796,10 @@ void WM_tooltip_init(struct bContext *C, struct wmWindow *win); void WM_tooltip_refresh(struct bContext *C, struct wmWindow *win); double WM_tooltip_time_closed(void); -/* wmGenericUserData */ +/* wm_utils.c */ +struct wmGenericCallback *WM_generic_callback_steal(struct wmGenericCallback *callback); +void WM_generic_callback_free(struct wmGenericCallback *callback); + void WM_generic_user_data_free(struct wmGenericUserData *user_data); #ifdef __cplusplus diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index d2e71496494..eddea3b2062 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -127,6 +127,12 @@ typedef struct wmGenericUserData { bool use_free; } wmGenericUserData; +typedef struct wmGenericCallback { + void (*exec)(struct bContext *C, void *user_data); + void *user_data; + void (*free_user_data)(void *user_data); +} wmGenericCallback; + /* ************** wmOperatorType ************************ */ /* flag */ 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); - } - } -} diff --git a/source/blender/windowmanager/wm_files.h b/source/blender/windowmanager/wm_files.h index e75626a4f30..0aa4357a8f4 100644 --- a/source/blender/windowmanager/wm_files.h +++ b/source/blender/windowmanager/wm_files.h @@ -25,6 +25,7 @@ #define __WM_FILES_H__ struct Main; +struct wmGenericCallback; struct wmOperatorType; /* wm_files.c */ @@ -40,15 +41,7 @@ void wm_homefile_read(struct bContext *C, bool *r_is_factory_startup); void wm_file_read_report(bContext *C, struct Main *bmain); -typedef struct wmGenericCallback { - void (*exec)(bContext *C, void *user_data); - void *user_data; - void (*free_user_data)(void *user_data); -} wmGenericCallback; - -wmGenericCallback *wm_generic_callback_steal(wmGenericCallback *callback); -void wm_generic_callback_free(wmGenericCallback *callback); -void wm_close_file_dialog(bContext *C, wmGenericCallback *post_action); +void wm_close_file_dialog(bContext *C, struct wmGenericCallback *post_action); bool wm_file_or_image_is_modified(const struct bContext *C); void WM_OT_save_homefile(struct wmOperatorType *ot); |