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/wm_utils.c | |
parent | 3184460ff7f4f660a70ec7a18a3a882eb2de57f8 (diff) |
Cleanup: add wm_utils.c for generic functions
Diffstat (limited to 'source/blender/windowmanager/intern/wm_utils.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_utils.c | 71 |
1 files changed, 71 insertions, 0 deletions
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); + } + } +} + +/** \} */ |