代码改变世界

Abiword中自定义字段对象流程分析

2011-04-29 13:12  netwy  阅读(374)  评论(0编辑  收藏  举报

1、定义对象的id,ap_String_Id.h

dcl(FIELD_Type_Custom, "Custom") //字段所属分类
dcl(FIELD_Custom_FieldCustom, "FieldCustom") // 字段

2、继承fp_FieldRun类,实现自定义字段

 

3、fp_Fields.h

_FIELDTYPE(CUSTOM, AP_STRING_ID_FIELD_Type_Custom)
_FIELD(CUSTOM, AP_STRING_ID_FIELD_Custom_FieldCustom, CustomField)

4、fp_Run.h

     6.1. 定义_FIELD、_FIELDTYPE宏

     6.2.根据fp_Fields.h定义fp_FieldTypesEnum、fp_FieldsEnum枚举

     6.3.根据fp_Fields.h定义fp_FieldTypeData、fp_FieldData结构数组

 

5、添加_FieldType枚举数

     FD_Custom

 

6、fl_BlockLayout::_doInsertFieldRun,实例化自定义字段

if(strcmp(pszType, "CustomField") == 0)
 {
  pNewRun = new fp_FieldCustomRun(this,   blockOffset, 1);
 }

7、pf_Frag_Object::pf_Frag_Object设置自定的类型

    if (0 == strcmp(pszType, "CustomField"))
    {
         fieldType = fd_Field::FD_Custom;
    }
    else
    {
          UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
          //Better than segfaulting I figure
          fieldType = fd_Field::FD_None;
     }

8、在删除Field时,在fp_Line::removeRun函数中做如下修改

if(pRun->getType() == FPRUN_FIELD)
 {
  getBlock()->getView()->setActiveFieldRun(NULL);
 }