RNA
[blender.git] / source / blender / editors / curve / editfont.c
index edc1f8aecaebe6ce832be22b156b64a30fe95e73..5389db9e2eebca4d309d5f55b395156e96490bdd 100644 (file)
@@ -226,7 +226,7 @@ void update_string(Curve *cu)
        wcs2utf8s(cu->str, ef->textbuf);
 }
 
-static int insert_into_textbuf(Object *obedit, unsigned long c)
+static int insert_into_textbuf(Object *obedit, uintptr_t c)
 {
        Curve *cu= obedit->data;
        
@@ -401,11 +401,11 @@ static int paste_file_invoke(bContext *C, wmOperator *op, wmEvent *event)
        return OPERATOR_RUNNING_MODAL;
 }
 
-void FONT_OT_paste_file(wmOperatorType *ot)
+void FONT_OT_file_paste(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Paste File";
-       ot->idname= "FONT_OT_paste_file";
+       ot->idname= "FONT_OT_file_paste";
        
        /* api callbacks */
        ot->exec= paste_file_exec;
@@ -449,11 +449,11 @@ static int paste_buffer_exec(bContext *C, wmOperator *op)
        return paste_file(C, NULL, filename);
 }
 
-void FONT_OT_paste_buffer(wmOperatorType *ot)
+void FONT_OT_buffer_paste(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Paste Buffer";
-       ot->idname= "FONT_OT_paste_buffer";
+       ot->idname= "FONT_OT_buffer_paste";
        
        /* api callbacks */
        ot->exec= paste_buffer_exec;
@@ -463,182 +463,96 @@ void FONT_OT_paste_buffer(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-/******************* XXX text to object operator ********************/
+/******************* text to object operator ********************/
 
-static void txt_export_to_object(Scene *scene, Object *obedit, Text *text)
+static void txt_add_object(bContext *C, TextLine *firstline, int totline, float offset[3])
 {
-       ID *id;
+       Scene *scene= CTX_data_scene(C);
        Curve *cu;
+       Object *obedit;
+       Base *base;
        struct TextLine *tmp;
-       int nchars = 0;
-//     char sdir[FILE_MAXDIR];
-//     char sfile[FILE_MAXFILE];
-
-       if(!text || !text->lines.first) return;
+       int nchars = 0, a;
 
-       id = (ID *)text;
+       obedit= add_object(scene, OB_FONT);
+       base= scene->basact;
 
-       if(obedit && obedit->type==OB_FONT) return;
-// XXX check_editmode(OB_FONT);
-       
-       add_object(scene, OB_FONT);
-
-       ED_object_base_init_from_view(NULL, BASACT); // XXX
-       obedit= BASACT->object;
+       ED_object_base_init_from_view(C, base);
        where_is_object(scene, obedit);
 
-       cu= obedit->data;
-
-/*     
-//             renames object, careful with long filenames.
+       obedit->loc[0] += offset[0];
+       obedit->loc[1] += offset[1];
+       obedit->loc[2] += offset[2];
 
-       if(text->name) {
-       //ID *find_id(char *type, char *name)   
-               BLI_split_dirfile(text->name, sdir, sfile);
-//             rename_id((ID *)obedit, sfile);
-               rename_id((ID *)cu, sfile);
-               id->us++;
-       }
-*/     
+       cu= obedit->data;
        cu->vfont= get_builtin_font();
        cu->vfont->id.us++;
 
-       tmp= text->lines.first;
-       while(cu->len<MAXTEXT && tmp) {
+       for(tmp=firstline, a=0; cu->len<MAXTEXT && a<totline; tmp=tmp->next, a++)
                nchars += strlen(tmp->line) + 1;
-               tmp = tmp->next;
-       }
 
        if(cu->str) MEM_freeN(cu->str);
        if(cu->strinfo) MEM_freeN(cu->strinfo); 
 
-       cu->str= MEM_mallocN(nchars+4, "str");
+       cu->str= MEM_callocN(nchars+4, "str");
        cu->strinfo= MEM_callocN((nchars+4)*sizeof(CharInfo), "strinfo");
-       cu->totbox= cu->actbox= 1;
-       cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "textbox");
-       cu->tb[0].w = cu->tb[0].h = 0.0;
+
+       cu->str[0]= '\0';
+       cu->len= 0;
+       cu->pos= 0;
        
-       tmp= text->lines.first;
-       strcpy(cu->str, tmp->line);
-       cu->len= strlen(tmp->line);
-       cu->pos= cu->len;
+       for(tmp=firstline, a=0; cu->len<MAXTEXT && a<totline; tmp=tmp->next, a++) {
+               strcat(cu->str, tmp->line);
+               cu->len+= strlen(tmp->line);
 
-       tmp= tmp->next;
+               if(tmp->next) {
+                       strcat(cu->str, "\n");
+                       cu->len++;
+               }
 
-       while(cu->len<MAXTEXT && tmp) {
-               strcat(cu->str, "\n");
-               strcat(cu->str, tmp->line);
-               cu->len+= strlen(tmp->line) + 1;
                cu->pos= cu->len;
-               tmp= tmp->next;
        }
 
-       make_editText(obedit);
-       ED_object_exit_editmode(NULL, EM_FREEDATA|EM_WAITCURSOR); // XXX
+       WM_event_add_notifier(C, NC_OBJECT|NA_ADDED, obedit);
 }
 
-static void txt_export_to_objects(Scene *scene, Object *obedit, Text *text)
+void ED_text_to_object(bContext *C, Text *text, int split_lines)
 {
-       RegionView3D *rv3d= NULL; // XXX
-       ID *id;
-       Curve *cu;
-       struct TextLine *curline;
-       int nchars;
-       int linenum = 0;
-       float offset[3] = {0.0,0.0,0.0};
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
+       TextLine *line;
+       float offset[3];
+       int linenum= 0;
 
        if(!text || !text->lines.first) return;
 
-       id = (ID *)text;
-
-       if(obedit && obedit->type==OB_FONT) return;
-// XXX check_editmode(OB_FONT);
-
-       curline = text->lines.first;
-       while(curline){ 
-               /*skip lines with no text, but still make space for them*/
-               if(curline->line[0] == '\0'){
-                       linenum++;
-                       curline = curline->next;
-                       continue;
-               }
-                       
-               nchars = 0;     
-               add_object(scene, OB_FONT);
-       
-               ED_object_base_init_from_view(NULL, BASACT); // XXX
-               obedit= BASACT->object;
-               where_is_object(scene, obedit); 
-               
-               /* Do the translation */
-               offset[0] = 0;
-               offset[1] = -linenum;
-               offset[2] = 0;
-       
-               Mat4Mul3Vecfl(rv3d->viewinv, offset);
-               
-               obedit->loc[0] += offset[0];
-               obedit->loc[1] += offset[1];
-               obedit->loc[2] += offset[2];
-               /* End Translation */
-                                       
-               cu= obedit->data;
-               
-               cu->vfont= get_builtin_font();
-               cu->vfont->id.us++;
-       
-               nchars = strlen(curline->line) + 1;
+       if(split_lines) {
+               for(line=text->lines.first; line; line=line->next) {
+                       /* skip lines with no text, but still make space for them */
+                       if(line->line[0] == '\0') {
+                               linenum++;
+                               continue;
+                       }
        
-               if(cu->str) MEM_freeN(cu->str);
-               if(cu->strinfo) MEM_freeN(cu->strinfo);         
+                       /* do the translation */
+                       offset[0] = 0;
+                       offset[1] = -linenum;
+                       offset[2] = 0;
        
-               cu->str= MEM_mallocN(nchars+4, "str");
-               cu->strinfo= MEM_callocN((nchars+4)*sizeof(CharInfo), "strinfo");
-               cu->totbox= cu->actbox= 1;
-               cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "textbox");
-               cu->tb[0].w = cu->tb[0].h = 0.0;
-               
-               strcpy(cu->str, curline->line);
-               cu->len= strlen(curline->line);
-               cu->pos= cu->len;
+                       if(rv3d)
+                               Mat4Mul3Vecfl(rv3d->viewinv, offset);
 
-               make_editText(obedit);
-               ED_object_exit_editmode(NULL, EM_FREEDATA|EM_WAITCURSOR); // XXX
+                       txt_add_object(C, line, 1, offset);
 
-               linenum++;
-               curline = curline->next;
+                       linenum++;
+               }
        }
-}
-
-static int text_to_object_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene= CTX_data_scene(C);
-       Object *obedit= CTX_data_edit_object(C);
-       Text *text= NULL; /// XXX retrieve this ..
-
-       if(RNA_boolean_get(op->ptr, "split_lines"))
-               txt_export_to_objects(scene, obedit, text);
-       else
-               txt_export_to_object(scene, obedit, text);
-
-       return OPERATOR_FINISHED;
-}
-
-void FONT_OT_text_to_object(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Text to Object";
-       ot->idname= "FONT_OT_text_to_object";
-       
-       /* api callbacks */
-       ot->exec= text_to_object_exec;
-       ot->poll= ED_operator_editfont; // XXX not correct
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       else {
+               offset[0]= 0.0f;
+               offset[1]= 0.0f;
+               offset[2]= 0.0f;
 
-       /* properties */
-       RNA_def_boolean(ot->srna, "split_lines", 0, "Split Lines", "Create one object per line in the text.");
+               txt_add_object(C, text->lines.first, BLI_countlist(&text->lines), offset);
+       }
 }
 
 /********************** utilities ***************************/
@@ -693,10 +607,10 @@ static int kill_selection(Object *obedit, int ins)        /* 1 == new character */
 /******************* set style operator ********************/
 
 static EnumPropertyItem style_items[]= {
-       {CU_BOLD, "BOLD", "Bold", ""},
-       {CU_ITALIC, "ITALIC", "Italic", ""},
-       {CU_UNDERLINE, "UNDERLINE", "Underline", ""},
-       {0, NULL, NULL, NULL}};
+       {CU_BOLD, "BOLD", 0, "Bold", ""},
+       {CU_ITALIC, "ITALIC", 0, "Italic", ""},
+       {CU_UNDERLINE, "UNDERLINE", 0, "Underline", ""},
+       {0, NULL, 0, NULL, NULL}};
 
 static int set_style(bContext *C, int style, int clear)
 {
@@ -732,11 +646,11 @@ static int set_style_exec(bContext *C, wmOperator *op)
        return set_style(C, style, clear);
 }
 
-void FONT_OT_set_style(wmOperatorType *ot)
+void FONT_OT_style_set(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Style";
-       ot->idname= "FONT_OT_set_style";
+       ot->idname= "FONT_OT_style_set";
        
        /* api callbacks */
        ot->exec= set_style_exec;
@@ -769,11 +683,11 @@ static int toggle_style_exec(bContext *C, wmOperator *op)
        return set_style(C, style, clear);
 }
 
-void FONT_OT_toggle_style(wmOperatorType *ot)
+void FONT_OT_style_toggle(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Toggle Style";
-       ot->idname= "FONT_OT_toggle_style";
+       ot->idname= "FONT_OT_style_toggle";
        
        /* api callbacks */
        ot->exec= toggle_style_exec;
@@ -813,11 +727,11 @@ static int set_material_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void FONT_OT_set_material(wmOperatorType *ot)
+void FONT_OT_material_set(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Material";
-       ot->idname= "FONT_OT_set_material";
+       ot->idname= "FONT_OT_material_set";
        
        /* api callbacks */
        ot->exec= set_material_exec;
@@ -855,11 +769,11 @@ static int copy_text_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void FONT_OT_copy_text(wmOperatorType *ot)
+void FONT_OT_text_copy(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Copy Text";
-       ot->idname= "FONT_OT_copy_text";
+       ot->idname= "FONT_OT_text_copy";
        
        /* api callbacks */
        ot->exec= copy_text_exec;
@@ -885,11 +799,11 @@ static int cut_text_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void FONT_OT_cut_text(wmOperatorType *ot)
+void FONT_OT_text_cut(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Cut Text";
-       ot->idname= "FONT_OT_cut_text";
+       ot->idname= "FONT_OT_text_cut";
        
        /* api callbacks */
        ot->exec= cut_text_exec;
@@ -942,11 +856,11 @@ static int paste_text_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void FONT_OT_paste_text(wmOperatorType *ot)
+void FONT_OT_text_paste(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Paste Text";
-       ot->idname= "FONT_OT_paste_text";
+       ot->idname= "FONT_OT_text_paste";
        
        /* api callbacks */
        ot->exec= paste_text_exec;
@@ -959,17 +873,17 @@ void FONT_OT_paste_text(wmOperatorType *ot)
 /************************ move operator ************************/
 
 static EnumPropertyItem move_type_items[]= {
-       {LINE_BEGIN, "LINE_BEGIN", "Line Begin", ""},
-       {LINE_END, "LINE_END", "Line End", ""},
-       {PREV_CHAR, "PREVIOUS_CHARACTER", "Previous Character", ""},
-       {NEXT_CHAR, "NEXT_CHARACTER", "Next Character", ""},
-       {PREV_WORD, "PREVIOUS_WORD", "Previous Word", ""},
-       {NEXT_WORD, "NEXT_WORD", "Next Word", ""},
-       {PREV_LINE, "PREVIOUS_LINE", "Previous Line", ""},
-       {NEXT_LINE, "NEXT_LINE", "Next Line", ""},
-       {PREV_PAGE, "PREVIOUS_PAGE", "Previous Page", ""},
-       {NEXT_PAGE, "NEXT_PAGE", "Next Page", ""},
-       {0, NULL, NULL, NULL}};
+       {LINE_BEGIN, "LINE_BEGIN", 0, "Line Begin", ""},
+       {LINE_END, "LINE_END", 0, "Line End", ""},
+       {PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
+       {NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
+       {PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
+       {NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
+       {PREV_LINE, "PREVIOUS_LINE", 0, "Previous Line", ""},
+       {NEXT_LINE, "NEXT_LINE", 0, "Next Line", ""},
+       {PREV_PAGE, "PREVIOUS_PAGE", 0, "Previous Page", ""},
+       {NEXT_PAGE, "NEXT_PAGE", 0, "Next Page", ""},
+       {0, NULL, 0, NULL, NULL}};
 
 static int move_cursor(bContext *C, int type, int select)
 {
@@ -1250,13 +1164,13 @@ void FONT_OT_line_break(wmOperatorType *ot)
 /******************* delete operator **********************/
 
 static EnumPropertyItem delete_type_items[]= {
-       {DEL_ALL, "ALL", "All", ""},
-       {DEL_NEXT_CHAR, "NEXT_CHARACTER", "Next Character", ""},
-       {DEL_PREV_CHAR, "PREVIOUS_CHARACTER", "Previous Character", ""},
-       {DEL_SELECTION, "SELECTION", "Selection", ""},
-       {DEL_NEXT_SEL, "NEXT_OR_SELECTION", "Next or Selection", ""},
-       {DEL_PREV_SEL, "PREVIOUS_OR_SELECTION", "Previous or Selection", ""},
-       {0, NULL, NULL, NULL}};
+       {DEL_ALL, "ALL", 0, "All", ""},
+       {DEL_NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
+       {DEL_PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
+       {DEL_SELECTION, "SELECTION", 0, "Selection", ""},
+       {DEL_NEXT_SEL, "NEXT_OR_SELECTION", 0, "Next or Selection", ""},
+       {DEL_PREV_SEL, "PREVIOUS_OR_SELECTION", 0, "Previous or Selection", ""},
+       {0, NULL, 0, NULL, NULL}};
 
 static int delete_exec(bContext *C, wmOperator *op)
 {
@@ -1376,7 +1290,7 @@ static int insert_text_invoke(bContext *C, wmOperator *op, wmEvent *evt)
        Curve *cu= obedit->data;
        EditFont *ef= cu->editfont;
        static int accentcode= 0;
-       unsigned long ascii = evt->ascii;
+       uintptr_t ascii = evt->ascii;
        int alt= evt->alt, shift= evt->shift, ctrl= evt->ctrl;
        int event= evt->type, val= evt->val;
        wchar_t inserted_text[2]= {0};
@@ -1460,11 +1374,11 @@ static int insert_text_invoke(bContext *C, wmOperator *op, wmEvent *evt)
        return OPERATOR_FINISHED;
 }
 
-void FONT_OT_insert_text(wmOperatorType *ot)
+void FONT_OT_text_insert(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Insert Text";
-       ot->idname= "FONT_OT_insert_text";
+       ot->idname= "FONT_OT_text_insert";
        
        /* api callbacks */
        ot->exec= insert_text_exec;
@@ -1493,7 +1407,7 @@ void make_editText(Object *obedit)
                ef->copybuf= MEM_callocN((MAXTEXT+4)*sizeof(wchar_t), "texteditcopybuf");
                ef->copybufinfo= MEM_callocN((MAXTEXT+4)*sizeof(CharInfo), "texteditcopybufinfo");      
                ef->oldstr= MEM_callocN((MAXTEXT+4)*sizeof(wchar_t), "oldstrbuf");
-               ef->oldstrinfo= MEM_callocN((MAXTEXT+4)*sizeof(wchar_t), "oldstrbuf");
+               ef->oldstrinfo= MEM_callocN((MAXTEXT+4)*sizeof(CharInfo), "oldstrbuf");
        }
        
        // Convert the original text to wchar_t
@@ -1551,9 +1465,9 @@ void free_editText(Object *obedit)
 /********************** set case operator *********************/
 
 static EnumPropertyItem case_items[]= {
-       {CASE_LOWER, "LOWER", "Lower", ""},
-       {CASE_UPPER, "UPPER", "Upper", ""},
-       {0, NULL, NULL, NULL}};
+       {CASE_LOWER, "LOWER", 0, "Lower", ""},
+       {CASE_UPPER, "UPPER", 0, "Upper", ""},
+       {0, NULL, 0, NULL, NULL}};
 
 static int set_case(bContext *C, int ccase)
 {
@@ -1595,11 +1509,11 @@ static int set_case_exec(bContext *C, wmOperator *op)
        return set_case(C, RNA_enum_get(op->ptr, "case"));
 }
 
-void FONT_OT_set_case(wmOperatorType *ot)
+void FONT_OT_case_set(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Case";
-       ot->idname= "FONT_OT_set_case";
+       ot->idname= "FONT_OT_case_set";
        
        /* api callbacks */
        ot->exec= set_case_exec;
@@ -1637,11 +1551,11 @@ static int toggle_case_exec(bContext *C, wmOperator *op)
        return set_case(C, ccase);
 }
 
-void FONT_OT_toggle_case(wmOperatorType *ot)
+void FONT_OT_case_toggle(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Toggle Case";
-       ot->idname= "FONT_OT_toggle_case";
+       ot->idname= "FONT_OT_case_toggle";
        
        /* api callbacks */
        ot->exec= toggle_case_exec;