doxygen: blender/editors tagged.
[blender.git] / source / blender / editors / curve / editfont.c
index ae34f30a4f16c34cd90521e287a02073a4e30e23..798a9d0f7cd49917e40162762fde050c2c97c0c5 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -15,7 +15,7 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/editors/curve/editfont.c
+ *  \ingroup edcurve
+ */
+
+
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
-#include "BLI_arithb.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
 
 #include "DNA_curve_types.h"
 #include "DNA_object_types.h"
 #include "DNA_vfont_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_text_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_userdef_types.h"
 
 #include "BKE_context.h"
 #include "BKE_curve.h"
 #include "BKE_depsgraph.h"
 #include "BKE_font.h"
-#include "BKE_global.h"
-#include "BKE_main.h"
+#include "BKE_library.h"
 #include "BKE_object.h"
 #include "BKE_report.h"
-#include "BKE_utildefines.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -70,6 +72,8 @@
 #include "ED_screen.h"
 #include "ED_util.h"
 
+#include "UI_interface.h"
+
 #include "curve_intern.h"
 
 #define MAXTEXT        32766
@@ -208,7 +212,7 @@ static char findaccent(char char1, unsigned int code)
 }
 
 
-void update_string(Curve *cu)
+static void update_string(Curve *cu)
 {
        EditFont *ef= cu->editfont;
        int len;
@@ -239,10 +243,7 @@ static int insert_into_textbuf(Object *obedit, uintptr_t c)
                ef->textbuf[cu->pos]= c;
                ef->textbufinfo[cu->pos] = cu->curinfo;
                ef->textbufinfo[cu->pos].kern = 0;
-               if(obedit->actcol>0)
-                       ef->textbufinfo[cu->pos].mat_nr = obedit->actcol;
-               else
-                       ef->textbufinfo[cu->pos].mat_nr = 0;
+               ef->textbufinfo[cu->pos].mat_nr = obedit->actcol;
                                        
                cu->pos++;
                cu->len++;
@@ -260,31 +261,29 @@ static void text_update_edited(bContext *C, Scene *scene, Object *obedit, int re
 {
        Curve *cu= obedit->data;
        EditFont *ef= cu->editfont;
-
-       if(cu->pos)
-               cu->curinfo = ef->textbufinfo[cu->pos-1];
-       else
-               cu->curinfo = ef->textbufinfo[0];
+       cu->curinfo = ef->textbufinfo[cu->pos?cu->pos-1:0];
        
        if(obedit->totcol>0)
-               obedit->actcol= ef->textbufinfo[cu->pos-1].mat_nr;
+               obedit->actcol= ef->textbufinfo[cu->pos?cu->pos-1:0].mat_nr;
+
+       if(mode == FO_EDIT)
+               update_string(cu);
 
-       update_string(cu);
        BKE_text_to_curve(scene, obedit, mode);
 
        if(recalc)
-               DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+               DAG_id_tag_update(obedit->data, 0);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 }
 
 /********************** insert lorem operator *********************/
 
-static int insert_lorem_exec(bContext *C, wmOperator *op)
+static int insert_lorem_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
-       char *p, *p2;
+       const char *p, *p2;
        int i;
-       static char *lastlorem;
+       static const char *lastlorem;
        
        if(lastlorem)
                p= lastlorem;
@@ -307,7 +306,7 @@ static int insert_lorem_exec(bContext *C, wmOperator *op)
        insert_into_textbuf(obedit, '\n');
        insert_into_textbuf(obedit, '\n');      
 
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       DAG_id_tag_update(obedit->data, 0);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 
        return OPERATOR_FINISHED;
@@ -317,6 +316,7 @@ void FONT_OT_insert_lorem(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Insert Lorem";
+       ot->description= "Insert placeholder text";
        ot->idname= "FONT_OT_insert_lorem";
        
        /* api callbacks */
@@ -332,7 +332,7 @@ void FONT_OT_insert_lorem(wmOperatorType *ot)
 /* note this handles both ascii and utf8 unicode, previously
  * there were 3 functions that did effectively the same thing. */
 
-static int paste_file(bContext *C, ReportList *reports, char *filename)
+static int paste_file(bContext *C, ReportList *reports, const char *filename)
 {
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
@@ -373,26 +373,26 @@ static int paste_file(bContext *C, ReportList *reports, char *filename)
        }
        MEM_freeN(strp);
 
-       text_update_edited(C, scene, obedit, 1, 0);
+       text_update_edited(C, scene, obedit, 1, FO_EDIT);
 
        return OPERATOR_FINISHED;
 }
 
 static int paste_file_exec(bContext *C, wmOperator *op)
 {
-       char *filename;
+       char *path;
        int retval;
        
-       filename= RNA_string_get_alloc(op->ptr, "filename", NULL, 0);
-       retval= paste_file(C, op->reports, filename);
-       MEM_freeN(filename);
+       path= RNA_string_get_alloc(op->ptr, "filepath", NULL, 0);
+       retval= paste_file(C, op->reports, path);
+       MEM_freeN(path);
 
        return retval;
 }
 
-static int paste_file_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int paste_file_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 {
-       if(RNA_property_is_set(op->ptr, "filename"))
+       if(RNA_property_is_set(op->ptr, "filepath"))
                return paste_file_exec(C, op);
 
        WM_event_add_fileselect(C, op); 
@@ -404,6 +404,7 @@ void FONT_OT_file_paste(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Paste File";
+       ot->description= "Paste contents from file";
        ot->idname= "FONT_OT_file_paste";
        
        /* api callbacks */
@@ -415,14 +416,14 @@ void FONT_OT_file_paste(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE);
+       WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH);
 }
 
 /******************* paste buffer operator ********************/
 
-static int paste_buffer_exec(bContext *C, wmOperator *op)
+static int paste_buffer_exec(bContext *C, wmOperator *UNUSED(op))
 {
-       char *filename;
+       const char *filename;
 
 #ifdef WIN32
        filename= "C:\\windows\\temp\\cutbuf.txt";
@@ -452,6 +453,7 @@ void FONT_OT_buffer_paste(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Paste Buffer";
+       ot->description= "Paste text from OS buffer";
        ot->idname= "FONT_OT_buffer_paste";
        
        /* api callbacks */
@@ -472,11 +474,13 @@ static void txt_add_object(bContext *C, TextLine *firstline, int totline, float
        Base *base;
        struct TextLine *tmp;
        int nchars = 0, a;
-
+       float rot[3] = {0.f, 0.f, 0.f};
+       
        obedit= add_object(scene, OB_FONT);
        base= scene->basact;
 
-       ED_object_base_init_from_view(C, base);
+       
+       ED_object_base_init_transform(C, base, NULL, rot); /* seems to assume view align ? TODO - look into this, could be an operator option */
        where_is_object(scene, obedit);
 
        obedit->loc[0] += offset[0];
@@ -538,7 +542,7 @@ void ED_text_to_object(bContext *C, Text *text, int split_lines)
                        offset[2] = 0;
        
                        if(rv3d)
-                               Mat4Mul3Vecfl(rv3d->viewinv, offset);
+                               mul_mat3_m4_v3(rv3d->viewinv, offset);
 
                        txt_add_object(C, line, 1, offset);
 
@@ -560,7 +564,7 @@ static short next_word(Curve *cu)
 {
        short s;
        for(s=cu->pos; (cu->str[s]) && (cu->str[s]!=' ') && (cu->str[s]!='\n') &&
-                       (cu->str[s]!=1) && (cu->str[s]!='\r'); s++);
+                                       (cu->str[s]!=1) && (cu->str[s]!='\r'); s++);
        if(cu->str[s]) return(s+1); else return(s);
 }
 
@@ -570,7 +574,7 @@ static short prev_word(Curve *cu)
        
        if(cu->pos==0) return(0);
        for(s=cu->pos-2; (cu->str[s]) && (cu->str[s]!=' ') && (cu->str[s]!='\n') &&
-                       (cu->str[s]!=1) && (cu->str[s]!='\r'); s--);
+                                       (cu->str[s]!=1) && (cu->str[s]!='\r'); s--);
        if(cu->str[s]) return(s+1); else return(s);
 }
 
@@ -606,9 +610,10 @@ static int kill_selection(Object *obedit, int ins) /* 1 == new character */
 /******************* set style operator ********************/
 
 static EnumPropertyItem style_items[]= {
-       {CU_BOLD, "BOLD", 0, "Bold", ""},
-       {CU_ITALIC, "ITALIC", 0, "Italic", ""},
-       {CU_UNDERLINE, "UNDERLINE", 0, "Underline", ""},
+       {CU_CHINFO_BOLD, "BOLD", 0, "Bold", ""},
+       {CU_CHINFO_ITALIC, "ITALIC", 0, "Italic", ""},
+       {CU_CHINFO_UNDERLINE, "UNDERLINE", 0, "Underline", ""},
+       {CU_CHINFO_SMALLCAPS, "SMALL_CAPS", 0, "Small Caps", ""},
        {0, NULL, 0, NULL, NULL}};
 
 static int set_style(bContext *C, int style, int clear)
@@ -628,7 +633,7 @@ static int set_style(bContext *C, int style, int clear)
                        ef->textbufinfo[i].flag |= style;
        }
 
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       DAG_id_tag_update(obedit->data, 0);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 
        return OPERATOR_FINISHED;
@@ -648,6 +653,7 @@ void FONT_OT_style_set(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Style";
+       ot->description= "Set font style";
        ot->idname= "FONT_OT_style_set";
        
        /* api callbacks */
@@ -658,7 +664,7 @@ void FONT_OT_style_set(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       RNA_def_enum(ot->srna, "style", style_items, CU_BOLD, "Style", "Style to set selection to.");
+       RNA_def_enum(ot->srna, "style", style_items, CU_CHINFO_BOLD, "Style", "Style to set selection to.");
        RNA_def_boolean(ot->srna, "clear", 0, "Clear", "Clear style rather than setting it.");
 }
 
@@ -685,6 +691,7 @@ void FONT_OT_style_toggle(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Toggle Style";
+       ot->description= "Toggle font style";
        ot->idname= "FONT_OT_style_toggle";
        
        /* api callbacks */
@@ -695,7 +702,7 @@ void FONT_OT_style_toggle(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       RNA_def_enum(ot->srna, "style", style_items, CU_BOLD, "Style", "Style to set selection to.");
+       RNA_def_enum(ot->srna, "style", style_items, CU_CHINFO_BOLD, "Style", "Style to set selection to.");
 }
 
 /******************* copy text operator ********************/
@@ -714,7 +721,7 @@ static void copy_selection(Object *obedit)
        }
 }
 
-static int copy_text_exec(bContext *C, wmOperator *op)
+static int copy_text_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
 
@@ -727,6 +734,7 @@ void FONT_OT_text_copy(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Copy Text";
+       ot->description= "Copy selected text to clipboard";
        ot->idname= "FONT_OT_text_copy";
        
        /* api callbacks */
@@ -736,7 +744,7 @@ void FONT_OT_text_copy(wmOperatorType *ot)
 
 /******************* cut text operator ********************/
 
-static int cut_text_exec(bContext *C, wmOperator *op)
+static int cut_text_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
@@ -748,7 +756,7 @@ static int cut_text_exec(bContext *C, wmOperator *op)
        copy_selection(obedit);
        kill_selection(obedit, 0);
 
-       text_update_edited(C, scene, obedit, 1, 0);
+       text_update_edited(C, scene, obedit, 1, FO_EDIT);
 
        return OPERATOR_FINISHED;
 }
@@ -757,6 +765,7 @@ void FONT_OT_text_cut(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Cut Text";
+       ot->description= "Cut selected text to clipboard";
        ot->idname= "FONT_OT_text_cut";
        
        /* api callbacks */
@@ -805,7 +814,7 @@ static int paste_text_exec(bContext *C, wmOperator *op)
        if(!paste_selection(obedit, op->reports))
                return OPERATOR_CANCELLED;
 
-       text_update_edited(C, scene, obedit, 1, 0);
+       text_update_edited(C, scene, obedit, 1, FO_EDIT);
 
        return OPERATOR_FINISHED;
 }
@@ -814,6 +823,7 @@ void FONT_OT_text_paste(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Paste Text";
+       ot->description= "Paste text from clipboard";
        ot->idname= "FONT_OT_text_paste";
        
        /* api callbacks */
@@ -845,14 +855,14 @@ static int move_cursor(bContext *C, int type, int select)
        Object *obedit= CTX_data_edit_object(C);
        Curve *cu= obedit->data;
        EditFont *ef= cu->editfont;
-       int cursmove= 0;
+       int cursmove= -1;
 
        switch(type) {
                case LINE_BEGIN:
                        if((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
                        while(cu->pos>0) {
                                if(ef->textbuf[cu->pos-1]=='\n') break;
-                               if(ef->textbufinfo[cu->pos-1].flag & CU_WRAP ) break;                           
+                               if(ef->textbufinfo[cu->pos-1].flag & CU_CHINFO_WRAP) break;                             
                                cu->pos--;
                        }               
                        cursmove=FO_CURS;
@@ -863,7 +873,7 @@ static int move_cursor(bContext *C, int type, int select)
                        while(cu->pos<cu->len) {
                                if(ef->textbuf[cu->pos]==0) break;
                                if(ef->textbuf[cu->pos]=='\n') break;
-                               if(ef->textbufinfo[cu->pos].flag & CU_WRAP ) break;
+                               if(ef->textbufinfo[cu->pos].flag & CU_CHINFO_WRAP ) break;
                                cu->pos++;
                        }
                        cursmove=FO_CURS;
@@ -915,7 +925,7 @@ static int move_cursor(bContext *C, int type, int select)
                        break;
        }
                
-       if(!cursmove)
+       if(cursmove == -1)
                return OPERATOR_CANCELLED;
 
        if(select == 0) {
@@ -949,6 +959,7 @@ void FONT_OT_move(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Move Cursor";
+       ot->description= "Move cursor to position type";
        ot->idname= "FONT_OT_move";
        
        /* api callbacks */
@@ -975,6 +986,7 @@ void FONT_OT_move_select(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Move Select";
+       ot->description= "Make selection from current cursor position to new cursor position type";
        ot->idname= "FONT_OT_move_select";
        
        /* api callbacks */
@@ -1007,7 +1019,7 @@ static int change_spacing_exec(bContext *C, wmOperator *op)
 
        ef->textbufinfo[cu->pos-1].kern = kern;
 
-       text_update_edited(C, scene, obedit, 1, 0);
+       text_update_edited(C, scene, obedit, 1, FO_EDIT);
 
        return OPERATOR_FINISHED;
 }
@@ -1016,6 +1028,7 @@ void FONT_OT_change_spacing(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Change Spacing";
+       ot->description= "Change font spacing";
        ot->idname= "FONT_OT_change_spacing";
        
        /* api callbacks */
@@ -1051,7 +1064,7 @@ static int change_character_exec(bContext *C, wmOperator *op)
 
        ef->textbuf[cu->pos - 1]= character;
 
-       text_update_edited(C, scene, obedit, 1, 0);
+       text_update_edited(C, scene, obedit, 1, FO_EDIT);
 
        return OPERATOR_FINISHED;
 }
@@ -1060,6 +1073,7 @@ void FONT_OT_change_character(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Change Character";
+       ot->description= "Change font character code";
        ot->idname= "FONT_OT_change_character";
        
        /* api callbacks */
@@ -1093,7 +1107,7 @@ static int line_break_exec(bContext *C, wmOperator *op)
 
        cu->selstart = cu->selend = 0;
 
-       text_update_edited(C, scene, obedit, 1, 0);
+       text_update_edited(C, scene, obedit, 1, FO_EDIT);
 
        return OPERATOR_FINISHED;
 }
@@ -1102,6 +1116,7 @@ void FONT_OT_line_break(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Line Break";
+       ot->description= "Insert line break at cursor position";
        ot->idname= "FONT_OT_line_break";
        
        /* api callbacks */
@@ -1182,7 +1197,7 @@ static int delete_exec(bContext *C, wmOperator *op)
                        return OPERATOR_CANCELLED;
        }
 
-       text_update_edited(C, scene, obedit, 1, 0);
+       text_update_edited(C, scene, obedit, 1, FO_EDIT);
 
        return OPERATOR_FINISHED;
 }
@@ -1191,6 +1206,7 @@ void FONT_OT_delete(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Delete";
+       ot->description= "Delete text by cursor position";
        ot->idname= "FONT_OT_delete";
        
        /* api callbacks */
@@ -1211,8 +1227,8 @@ static int insert_text_exec(bContext *C, wmOperator *op)
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        char *inserted_utf8;
-       wchar_t *inserted_text, first;
-       int len;
+       wchar_t *inserted_text;
+       int a, len;
 
        if(!RNA_property_is_set(op->ptr, "text"))
                return OPERATOR_CANCELLED;
@@ -1222,17 +1238,15 @@ static int insert_text_exec(bContext *C, wmOperator *op)
 
        inserted_text= MEM_callocN(sizeof(wchar_t)*(len+1), "FONT_insert_text");
        utf8towchar(inserted_text, inserted_utf8);
-       first= inserted_text[0];
+
+       for(a=0; a<len; a++)
+               insert_into_textbuf(obedit, inserted_text[a]);
 
        MEM_freeN(inserted_text);
        MEM_freeN(inserted_utf8);
 
-       if(!first)
-               return OPERATOR_CANCELLED;
-
-       insert_into_textbuf(obedit, first);
        kill_selection(obedit, 1);
-       text_update_edited(C, scene, obedit, 1, 0);
+       text_update_edited(C, scene, obedit, 1, FO_EDIT);
 
        return OPERATOR_FINISHED;
 }
@@ -1251,6 +1265,12 @@ static int insert_text_invoke(bContext *C, wmOperator *op, wmEvent *evt)
 
        if(RNA_property_is_set(op->ptr, "text"))
                return insert_text_exec(C, op);
+
+       if(RNA_property_is_set(op->ptr, "accent")) {
+               if(cu->len!=0 && cu->pos>0)
+                       accentcode= 1;
+               return OPERATOR_FINISHED;
+       }
        
        /* tab should exit editmode, but we allow it to be typed using modifier keys */
        if(event==TABKEY) {
@@ -1300,12 +1320,12 @@ static int insert_text_invoke(bContext *C, wmOperator *op, wmEvent *evt)
                        }
                        
                        kill_selection(obedit, 1);
-                       text_update_edited(C, scene, obedit, 1, 0);
+                       text_update_edited(C, scene, obedit, 1, FO_EDIT);
                }
                else {
                        inserted_text[0]= ascii;
                        insert_into_textbuf(obedit, ascii);
-                       text_update_edited(C, scene, obedit, 1, 0);
+                       text_update_edited(C, scene, obedit, 1, FO_EDIT);
                }
        }
        else if(val && event == BACKSPACEKEY) {
@@ -1325,6 +1345,9 @@ static int insert_text_invoke(bContext *C, wmOperator *op, wmEvent *evt)
                RNA_string_set(op->ptr, "text", inserted_utf8);
        }
 
+       /* reset property? */
+       accentcode= 0;
+       
        return OPERATOR_FINISHED;
 }
 
@@ -1332,6 +1355,7 @@ void FONT_OT_text_insert(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Insert Text";
+       ot->description= "Insert text at cursor position";
        ot->idname= "FONT_OT_text_insert";
        
        /* api callbacks */
@@ -1344,8 +1368,102 @@ void FONT_OT_text_insert(wmOperatorType *ot)
 
        /* properties */
        RNA_def_string(ot->srna, "text", "", 0, "Text", "Text to insert at the cursor position.");
+       RNA_def_boolean(ot->srna, "accent", 0, "Accent mode", "Next typed character will strike through previous, for special character input.");
 }
 
+
+/*********************** textbox add operator *************************/
+static int textbox_poll(bContext *C)
+{
+       Object *ob = CTX_data_active_object(C);
+       
+       if (!ED_operator_object_active_editable(C) ) return 0;
+       if (ob->type != OB_FONT) return 0;
+       
+       return 1;
+}
+
+static int textbox_add_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       Object *obedit= CTX_data_active_object(C);
+       Curve *cu= obedit->data;
+       int i;
+       
+       if (cu->totbox < 256) {
+               for (i = cu->totbox; i>cu->actbox; i--) cu->tb[i]= cu->tb[i-1];
+               cu->tb[cu->actbox]= cu->tb[cu->actbox-1];
+               cu->actbox++;
+               cu->totbox++;
+       }
+       
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+       return OPERATOR_FINISHED;
+}
+
+void FONT_OT_textbox_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Textbox";
+       ot->description= "Add a new text box";
+       ot->idname= "FONT_OT_textbox_add";
+       
+       /* api callbacks */
+       ot->exec= textbox_add_exec;
+       ot->poll= textbox_poll;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       
+}
+
+
+
+/*********************** textbox remove operator *************************/
+
+
+
+static int textbox_remove_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_active_object(C);
+       Curve *cu= obedit->data;
+       int i;
+       int index = RNA_int_get(op->ptr, "index");
+       
+       
+       if (cu->totbox > 1) {
+               for (i = index; i < cu->totbox; i++) cu->tb[i]= cu->tb[i+1];
+               cu->totbox--;
+               if (cu->actbox >= index)
+                       cu->actbox--;
+       }
+       
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+       
+       return OPERATOR_FINISHED;
+}
+
+void FONT_OT_textbox_remove(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Remove Textbox";
+       ot->description= "Remove the textbox";
+       ot->idname= "FONT_OT_textbox_remove";
+       
+       /* api callbacks */
+       ot->exec= textbox_remove_exec;
+       ot->poll= textbox_poll;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "The current text box.", 0, INT_MAX);
+       
+       
+}
+
+
+
 /***************** editmode enter/exit ********************/
 
 void make_editText(Object *obedit)
@@ -1453,7 +1571,7 @@ static int set_case(bContext *C, int ccase)
                }
        }
 
-       text_update_edited(C, scene, obedit, 1, 0);
+       text_update_edited(C, scene, obedit, 1, FO_EDIT);
 
        return OPERATOR_FINISHED;
 }
@@ -1467,6 +1585,7 @@ void FONT_OT_case_set(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Case";
+       ot->description= "Set font case";
        ot->idname= "FONT_OT_case_set";
        
        /* api callbacks */
@@ -1482,7 +1601,7 @@ void FONT_OT_case_set(wmOperatorType *ot)
 
 /********************** toggle case operator *********************/
 
-static int toggle_case_exec(bContext *C, wmOperator *op)
+static int toggle_case_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
        Curve *cu= obedit->data;
@@ -1509,6 +1628,7 @@ void FONT_OT_case_toggle(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Toggle Case";
+       ot->description= "Toggle font case";
        ot->idname= "FONT_OT_case_toggle";
        
        /* api callbacks */
@@ -1519,6 +1639,146 @@ void FONT_OT_case_toggle(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/* **************** Open Font ************** */
+
+static void font_ui_template_init(bContext *C, wmOperator *op)
+{
+       PropertyPointerRNA *pprop;
+       
+       op->customdata= pprop= MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
+       uiIDContextProperty(C, &pprop->ptr, &pprop->prop);
+}
+
+static int open_cancel(bContext *UNUSED(C), wmOperator *op)
+{
+       MEM_freeN(op->customdata);
+       op->customdata= NULL;
+       return OPERATOR_CANCELLED;
+}
+
+static int open_exec(bContext *C, wmOperator *op)
+{
+       VFont *font;
+       PropertyPointerRNA *pprop;
+       PointerRNA idptr;
+       char str[FILE_MAX];
+       RNA_string_get(op->ptr, "filepath", str);
+
+       font = load_vfont(str);
+
+       if(!font) {
+               if(op->customdata) MEM_freeN(op->customdata);
+               return OPERATOR_CANCELLED;
+       }
+
+       if(!op->customdata)
+               font_ui_template_init(C, op);
+       
+       /* hook into UI */
+       pprop= op->customdata;
+
+       if(pprop->prop) {
+               /* when creating new ID blocks, use is already 1, but RNA
+                * pointer se also increases user, so this compensates it */
+               font->id.us--;
+       
+               RNA_id_pointer_create(&font->id, &idptr);
+               RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
+               RNA_property_update(C, &pprop->ptr, pprop->prop);
+       }
+
+       MEM_freeN(op->customdata);
+
+       return OPERATOR_FINISHED;
+}
+
+static int open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
+{
+       VFont *font=NULL;
+       char *path;
+
+       PointerRNA idptr;
+       PropertyPointerRNA *pprop;
+
+       font_ui_template_init(C, op);
+
+       /* hook into UI */
+       pprop= op->customdata;
+
+       if(pprop->prop) {
+               idptr= RNA_property_pointer_get((PointerRNA *)pprop, pprop->prop);
+               font= idptr.id.data;
+       }
+
+       path = (font && strcmp(font->name, FO_BUILTIN_NAME) != 0)? font->name: U.fontdir;
+       
+       if(!RNA_property_is_set(op->ptr, "relative_path"))
+               RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
+               
+       if(RNA_property_is_set(op->ptr, "filepath"))
+               return open_exec(C, op);
+
+       RNA_string_set(op->ptr, "filepath", path);
+       WM_event_add_fileselect(C, op); 
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+void FONT_OT_open(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Open";
+       ot->idname= "FONT_OT_open";
+       
+       /* api callbacks */
+       ot->exec= open_exec;
+       ot->invoke= open_invoke;
+       ot->cancel= open_cancel;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* properties */
+       WM_operator_properties_filesel(ot, FOLDERFILE|FTFONTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH|WM_FILESEL_RELPATH);
+}
+
+/******************* delete operator *********************/
+
+static int font_unlink_exec(bContext *C, wmOperator *op)
+{
+       VFont *builtin_font;
+
+       PointerRNA idptr;
+       PropertyPointerRNA pprop;
+
+       uiIDContextProperty(C, &pprop.ptr, &pprop.prop);
+       
+       if(pprop.prop==NULL) {
+               BKE_report(op->reports, RPT_ERROR, "Incorrect context for running font unlink");
+               return OPERATOR_CANCELLED;
+       }
+
+       builtin_font = get_builtin_font();
+
+       RNA_id_pointer_create(&builtin_font->id, &idptr);
+       RNA_property_pointer_set(&pprop.ptr, pprop.prop, idptr);
+       RNA_property_update(C, &pprop.ptr, pprop.prop);
+
+       return OPERATOR_FINISHED;
+}
+
+void FONT_OT_unlink(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Unlink";
+       ot->idname= "FONT_OT_unlink";
+       ot->description= "Unlink active font data block";
+       
+       /* api callbacks */
+       ot->exec= font_unlink_exec;
+}
+
+
 /* **************** undo for font object ************** */
 
 static void undoFont_to_editFont(void *strv, void *ecu)
@@ -1572,8 +1832,7 @@ static void *get_undoFont(bContext *C)
 }
 
 /* and this is all the undo system needs to know */
-void undo_push_font(bContext *C, char *name)
+void undo_push_font(bContext *C, const char *name)
 {
        undo_editmode_push(C, name, get_undoFont, free_undoFont, undoFont_to_editFont, editFont_to_undoFont, NULL);
 }
-