Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-01-06 03:05:08 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-01-06 03:05:08 +0300
commit62f2b751f8c2c94bd783ce3d9bef6fc5c7d783c7 (patch)
treecf39c4cd92ea7556c07c94c890deca2cc2044b18 /source/blender
parentffd06de470b0695adac70ada9ab3719bcd4d0e5f (diff)
UI: refactor button string get/set into functions.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/editors/interface/interface.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 69ff1e78562..0b1d1c8c30c 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2164,6 +2164,32 @@ bool ui_but_string_set_eval_num(bContext *C, uiBut *but, const char *str, double
return ok;
}
+/* just the assignment/free part */
+static void ui_but_string_set_internal(uiBut *but, const char *str, size_t str_len)
+{
+ BLI_assert(str_len == strlen(str));
+ BLI_assert(but->str == NULL);
+ str_len += 1;
+
+ if (str_len > UI_MAX_NAME_STR) {
+ but->str = MEM_mallocN(str_len, "ui_def_but str");
+ }
+ else {
+ but->str = but->strdata;
+ }
+ memcpy(but->str, str, str_len);
+}
+
+static void ui_but_string_free_internal(uiBut *but)
+{
+ if (but->str) {
+ if (but->str != but->strdata) {
+ MEM_freeN(but->str);
+ }
+ /* must call 'ui_but_string_set_internal' after */
+ but->str = NULL;
+ }
+}
bool ui_but_string_set(bContext *C, uiBut *but, const char *str)
{
@@ -2647,18 +2673,9 @@ void ui_but_update(uiBut *but)
if (RNA_property_enum_name_gettexted(but->block->evil_C,
&but->rnapoin, but->rnaprop, value, &buf))
{
- if (but->str == but->strdata) {
- if (strlen(buf) < sizeof(but->strdata)) {
- BLI_strncpy(but->str, buf, sizeof(but->strdata));
- }
- else {
- but->str = BLI_strdup(buf);
- }
- }
- else {
- MEM_SAFE_FREE(but->str);
- but->str = BLI_strdup(buf);
- }
+ size_t slen = strlen(buf);
+ ui_but_string_free_internal(but);
+ ui_but_string_set_internal(but, buf, slen);
}
}
}
@@ -3066,13 +3083,7 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str,
but->retval = retval;
slen = strlen(str);
- if (slen >= UI_MAX_NAME_STR) {
- but->str = MEM_mallocN(slen + 1, "ui_def_but str");
- }
- else {
- but->str = but->strdata;
- }
- memcpy(but->str, str, slen + 1);
+ ui_but_string_set_internal(but, str, slen);
but->rect.xmin = x;
but->rect.ymin = y;