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

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

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);
 }

    

原文地址:https://www.cnblogs.com/songtzu/p/3539779.html