diff options
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/idtype.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_id.c | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_id_delete.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 195 |
4 files changed, 114 insertions, 93 deletions
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c index 322e1f7e822..3ff8a1bebd5 100644 --- a/source/blender/blenkernel/intern/idtype.c +++ b/source/blender/blenkernel/intern/idtype.c @@ -68,7 +68,7 @@ static void id_type_init(void) INIT_TYPE(ID_WO); INIT_TYPE(ID_SCR); // INIT_TYPE(ID_VF); - // INIT_TYPE(ID_TXT); + INIT_TYPE(ID_TXT); // INIT_TYPE(ID_SPK); // INIT_TYPE(ID_SO); INIT_TYPE(ID_GR); diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index 252b2499905..b74bb134dd3 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -516,9 +516,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags } return true; case ID_TXT: - if (!test) { - BKE_text_make_local(bmain, (Text *)id, flags); - } + BLI_assert(0); return true; case ID_SO: if (!test) { @@ -739,7 +737,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag) BLI_assert(0); break; case ID_TXT: - BKE_text_copy_data(bmain, (Text *)*r_newid, (Text *)id, flag); + BLI_assert(0); break; case ID_GR: BLI_assert(0); @@ -1363,7 +1361,7 @@ void BKE_libblock_init_empty(ID *id) BKE_vfont_init((VFont *)id); break; case ID_TXT: - BKE_text_init((Text *)id); + BLI_assert(0); break; case ID_SO: /* Another fuzzy case, think NULLified content is OK here... */ diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c index 492de2b14ef..634e7c59c08 100644 --- a/source/blender/blenkernel/intern/lib_id_delete.c +++ b/source/blender/blenkernel/intern/lib_id_delete.c @@ -187,7 +187,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag)) BKE_vfont_free((VFont *)id); break; case ID_TXT: - BKE_text_free((Text *)id); + BLI_assert(0); break; case ID_SPK: BKE_speaker_free((Speaker *)id); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index c20ef21f486..847cd6841fe 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -37,6 +37,8 @@ #include "BLI_listbase.h" #include "BLI_fileops.h" +#include "BLT_translation.h" + #include "DNA_constraint_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" @@ -47,6 +49,7 @@ #include "DNA_node_types.h" #include "DNA_material_types.h" +#include "BKE_idtype.h" #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_text.h" @@ -86,37 +89,100 @@ /***/ +/****************************** Prototypes ************************/ + static void txt_pop_first(Text *text); static void txt_pop_last(Text *text); static void txt_delete_line(Text *text, TextLine *line); static void txt_delete_sel(Text *text); static void txt_make_dirty(Text *text); -/***/ +/****************************** Text Datablock ************************/ + +static void text_init_data(ID *id) +{ + Text *text = (Text *)id; + TextLine *tmp; + + BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(text, id)); + + text->name = NULL; + + text->nlines = 1; + text->flags = TXT_ISDIRTY | TXT_ISMEM; + if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE) == 0) { + text->flags |= TXT_TABSTOSPACES; + } + + BLI_listbase_clear(&text->lines); + + tmp = (TextLine *)MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *)MEM_mallocN(1, "textline_string"); + tmp->format = NULL; + + tmp->line[0] = 0; + tmp->len = 0; + + tmp->next = NULL; + tmp->prev = NULL; + + BLI_addhead(&text->lines, tmp); + + text->curl = text->lines.first; + text->curc = 0; + text->sell = text->lines.first; + text->selc = 0; +} /** - * \note caller must handle `compiled` member. + * Only copy internal data of Text ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. + * + * WARNING! This function will not handle ID user count! + * + * \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more). */ -void BKE_text_free_lines(Text *text) +static void text_copy_data(Main *UNUSED(bmain), + ID *id_dst, + const ID *id_src, + const int UNUSED(flag)) { - for (TextLine *tmp = text->lines.first, *tmp_next; tmp; tmp = tmp_next) { - tmp_next = tmp->next; - MEM_freeN(tmp->line); - if (tmp->format) { - MEM_freeN(tmp->format); - } - MEM_freeN(tmp); + Text *text_dst = (Text *)id_dst; + const Text *text_src = (Text *)id_src; + + /* File name can be NULL. */ + if (text_src->name) { + text_dst->name = BLI_strdup(text_src->name); } - BLI_listbase_clear(&text->lines); + text_dst->flags |= TXT_ISDIRTY; - text->curl = text->sell = NULL; + BLI_listbase_clear(&text_dst->lines); + text_dst->curl = text_dst->sell = NULL; + text_dst->compiled = NULL; + + /* Walk down, reconstructing. */ + for (TextLine *line_src = text_src->lines.first; line_src; line_src = line_src->next) { + TextLine *line_dst = MEM_mallocN(sizeof(*line_dst), __func__); + + line_dst->line = BLI_strdup(line_src->line); + line_dst->format = NULL; + line_dst->len = line_src->len; + + BLI_addtail(&text_dst->lines, line_dst); + } + + text_dst->curl = text_dst->sell = text_dst->lines.first; + text_dst->curc = text_dst->selc = 0; } /** Free (or release) any data used by this text (does not free the text itself). */ -void BKE_text_free(Text *text) +static void text_free_data(ID *id) { /* No animdata here. */ + Text *text = (Text *)id; BKE_text_free_lines(text); @@ -126,38 +192,41 @@ void BKE_text_free(Text *text) #endif } -void BKE_text_init(Text *ta) -{ - TextLine *tmp; +IDTypeInfo IDType_ID_TXT = { + .id_code = ID_TXT, + .id_filter = FILTER_ID_TXT, + .main_listbase_index = INDEX_ID_TXT, + .struct_size = sizeof(Text), + .name = "Text", + .name_plural = "texts", + .translation_context = BLT_I18NCONTEXT_ID_TEXT, + .flags = 0, - BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ta, id)); + .init_data = text_init_data, + .copy_data = text_copy_data, + .free_data = text_free_data, + .make_local = NULL, +}; - ta->name = NULL; +/***/ - ta->nlines = 1; - ta->flags = TXT_ISDIRTY | TXT_ISMEM; - if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE) == 0) { - ta->flags |= TXT_TABSTOSPACES; +/** + * \note caller must handle `compiled` member. + */ +void BKE_text_free_lines(Text *text) +{ + for (TextLine *tmp = text->lines.first, *tmp_next; tmp; tmp = tmp_next) { + tmp_next = tmp->next; + MEM_freeN(tmp->line); + if (tmp->format) { + MEM_freeN(tmp->format); + } + MEM_freeN(tmp); } - BLI_listbase_clear(&ta->lines); - - tmp = (TextLine *)MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line = (char *)MEM_mallocN(1, "textline_string"); - tmp->format = NULL; - - tmp->line[0] = 0; - tmp->len = 0; - - tmp->next = NULL; - tmp->prev = NULL; - - BLI_addhead(&ta->lines, tmp); + BLI_listbase_clear(&text->lines); - ta->curl = ta->lines.first; - ta->curc = 0; - ta->sell = ta->lines.first; - ta->selc = 0; + text->curl = text->sell = NULL; } Text *BKE_text_add(Main *bmain, const char *name) @@ -168,7 +237,7 @@ Text *BKE_text_add(Main *bmain, const char *name) /* Texts always have 'real' user (see also read code). */ id_us_ensure_real(&ta->id); - BKE_text_init(ta); + text_init_data(&ta->id); return ta; } @@ -393,47 +462,6 @@ Text *BKE_text_load(Main *bmain, const char *file, const char *relpath) return BKE_text_load_ex(bmain, file, relpath, false); } -/** - * Only copy internal data of Text ID from source - * to already allocated/initialized destination. - * You probably never want to use that directly, - * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. - * - * WARNING! This function will not handle ID user count! - * - * \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more). - */ -void BKE_text_copy_data(Main *UNUSED(bmain), - Text *ta_dst, - const Text *ta_src, - const int UNUSED(flag)) -{ - /* file name can be NULL */ - if (ta_src->name) { - ta_dst->name = BLI_strdup(ta_src->name); - } - - ta_dst->flags |= TXT_ISDIRTY; - - BLI_listbase_clear(&ta_dst->lines); - ta_dst->curl = ta_dst->sell = NULL; - ta_dst->compiled = NULL; - - /* Walk down, reconstructing */ - for (TextLine *line_src = ta_src->lines.first; line_src; line_src = line_src->next) { - TextLine *line_dst = MEM_mallocN(sizeof(*line_dst), __func__); - - line_dst->line = BLI_strdup(line_src->line); - line_dst->format = NULL; - line_dst->len = line_src->len; - - BLI_addtail(&ta_dst->lines, line_dst); - } - - ta_dst->curl = ta_dst->sell = ta_dst->lines.first; - ta_dst->curc = ta_dst->selc = 0; -} - Text *BKE_text_copy(Main *bmain, const Text *ta) { Text *ta_copy; @@ -441,11 +469,6 @@ Text *BKE_text_copy(Main *bmain, const Text *ta) return ta_copy; } -void BKE_text_make_local(Main *bmain, Text *text, const int flags) -{ - BKE_lib_id_make_local_generic(bmain, &text->id, flags); -} - void BKE_text_clear(Text *text) /* called directly from rna */ { txt_sel_all(text); |