Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef FL_AUTONUM_H
00024 #define FL_AUTONUM_H
00025
00026 #include <algorithm>
00027 #include <functional>
00028 #include <memory>
00029 #include <string>
00030 #include <unordered_set>
00031 #include <vector>
00032
00033 #include "ut_types.h"
00034 #include "ut_misc.h"
00035 #include "pt_Types.h"
00036 #include "fl_AutoLists.h"
00037
00038 #if defined(__MINGW32__)
00039 #undef snprintf
00040 #define _GLIBCXX_USE_C99_DYNAMIC 1
00041 #endif
00042
00043
00044 class fl_BlockLayout;
00045 class fl_Layout;
00046 class pf_Frag_Strux;
00047 class PD_Document;
00048 class FV_View;
00049
00050 class fl_AutoNum;
00051
00052 typedef std::shared_ptr<fl_AutoNum> fl_AutoNumPtr;
00053 typedef std::shared_ptr<const fl_AutoNum> fl_AutoNumConstPtr;
00054
00055 class ABI_EXPORT fl_AutoNum
00056 : public std::enable_shared_from_this<fl_AutoNum>
00057 {
00058 private:
00059 class ItemStorage {
00060 public:
00061 typedef std::vector<pf_Frag_Strux*>::size_type size_type;
00062 typedef std::vector<pf_Frag_Strux*>::value_type value_type;
00063
00064 void addItem(pf_Frag_Strux* pItem);
00065 void deleteNthItem(size_type n);
00066 UT_sint32 findItem(const pf_Frag_Strux* pItem) const {
00067 auto iter = std::find(m_vec.cbegin(), m_vec.cend(), pItem);
00068 if (iter == m_vec.cend()) {
00069 return -1;
00070 }
00071 return iter - m_vec.cbegin();
00072 }
00073 pf_Frag_Strux* front() const {
00074 return m_vec.front();
00075 }
00076 pf_Frag_Strux* back() const {
00077 return m_vec.back();
00078 }
00079 size_type size() const {
00080 return m_vec.size();
00081 }
00082 bool empty() const {
00083 return m_vec.empty();
00084 }
00085 pf_Frag_Strux* at(size_type n) const {
00086 return m_vec.at(n);
00087 }
00088
00089 bool hasItem(const pf_Frag_Strux* pItem) const;
00090 void insertItemAt(pf_Frag_Strux* pItem, size_type idx);
00091 void sort(const std::function<bool(const value_type &, const value_type &)> & compar) {
00092 std::sort(m_vec.begin(), m_vec.end(), compar);
00093 }
00094 private:
00095 std::vector<pf_Frag_Strux*> m_vec;
00096 std::unordered_set<const pf_Frag_Strux*> m_set;
00097 };
00098 public:
00099 fl_AutoNum( UT_uint32 id,
00100 UT_uint32 parent_id,
00101 FL_ListType lType,
00102 UT_uint32 start,
00103 const gchar * lDelim,
00104 const gchar * lDecimal,
00105 PD_Document * pDoc,
00106 FV_View * pView);
00107
00108 ~fl_AutoNum();
00109
00110 void fixHierarchy(void);
00111
00112 const UT_UCSChar * getLabel(const pf_Frag_Strux*) const;
00113 void addItem(pf_Frag_Strux* pItem);
00114 FL_ListType getType() const;
00115 UT_uint32 getValue(const pf_Frag_Strux*) const;
00116 UT_uint32 getLevel() const { return m_iLevel; }
00117 UT_uint32 getNumLabels() const;
00118 bool checkReference(const fl_AutoNum & pAuto) const;
00119
00120 void setLevel(UT_uint32 level) { m_iLevel = level; }
00121 UT_sint32 getPositionInList(const pf_Frag_Strux* pItem) const;
00122 void setListType(FL_ListType lType);
00123 void setDelim(const gchar * pszDelim);
00124 void setDelim(const std::string & delim)
00125 {
00126 setDelim(delim.c_str());
00127 }
00128 const gchar * getDelim() const;
00129 void setDecimal(const gchar * pszDecimal);
00130 void setDecimal(const std::string & decimal)
00131 {
00132 setDecimal(decimal.c_str());
00133 }
00134 const gchar * getDecimal() const;
00135 bool isDirty() const;
00136 UT_uint16 getStartValue() const { return m_iStartValue; }
00137
00138 UT_uint32 getStartValue32() const;
00139 void setStartValue(UT_uint32 start);
00140
00141 void insertFirstItem(pf_Frag_Strux* pItem,
00142 pf_Frag_Strux* pLast,
00143 bool bDoFix=true);
00144 void insertItem(pf_Frag_Strux* pItem, const pf_Frag_Strux* pBefore, bool bDoFix = true);
00145 void prependItem(pf_Frag_Strux* pItem, const pf_Frag_Strux* pAfter, bool bDoFix = true);
00146 void removeItem(const pf_Frag_Strux* pItem);
00147 pf_Frag_Strux* getParentItem() const;
00148 void setParentItem(pf_Frag_Strux* pItem);
00149 bool isContainedByList(pf_Frag_Strux* pItem) const;
00150 pf_Frag_Strux* getNthBlock(UT_uint32 i) const;
00151 pf_Frag_Strux* getPrevInList(const pf_Frag_Strux* pItem) const;
00152
00153 bool isItem(const pf_Frag_Strux* pItem) const;
00154 bool doesItemHaveLabel(const fl_BlockLayout * pItem) const;
00155 bool isEmpty(void) const;
00156 pf_Frag_Strux* getFirstItem(void) const;
00157 pf_Frag_Strux* getLastItem(void) const;
00158 bool isLastOnLevel(const pf_Frag_Strux* pItem) const;
00159
00160 fl_AutoNumPtr getParent(void) const { return m_pParent; }
00161 fl_AutoNumPtr getActiveParent(void) const;
00162 fl_AutoNumConstPtr getAutoNumFromSdh(const pf_Frag_Strux* sdh) const;
00163 void fixListOrder(void);
00164 void markAsDirty(void);
00165 void findAndSetParentItem(void);
00166 void setAsciiOffset(UT_uint32 new_asciioffset);
00167
00168 void update(UT_uint32 start);
00169 bool isUpdating(void) const { return m_bUpdatingItems; }
00170 UT_uint32 getID() const { return m_iID; }
00171 UT_uint32 getParentID() const { return m_iParentID; }
00172 bool isIDSomeWhere(UT_uint32 ID) const;
00173 static char * dec2roman(UT_sint32 value, bool lower);
00174 static char * dec2ascii(UT_sint32 value, UT_uint32 offset);
00175 static void dec2hebrew(UT_UCSChar labelStr[], UT_uint32 * insPoint, UT_sint32 value);
00176 void getAttributes(std::vector<std::string>&v,
00177 bool bEscapeXML) const;
00178 PD_Document * getDoc(void) const
00179 {return m_pDoc;}
00180 pf_Frag_Strux* getLastItemInHeiracy(void) const;
00181 protected:
00182 void _setParent(const fl_AutoNumPtr & pParent);
00183 void _setParentID(UT_uint32 iParentID);
00184 void _calculateLabelStr(UT_uint32 depth);
00185 void _getLabelstr( UT_UCSChar labelStr[],
00186 UT_uint32 * insPoint,
00187 UT_uint32 depth,
00188 const pf_Frag_Strux* pLayout) const;
00189 bool _updateItems(UT_sint32 start, const pf_Frag_Strux* notMe);
00190 UT_uint32 _getLevelValue(const fl_AutoNumConstPtr & pAutoNum) const;
00191
00192 fl_AutoNumPtr m_pParent;
00193
00194 private:
00195 ItemStorage m_items;
00196 protected:
00197 PD_Document * m_pDoc;
00198 FV_View * m_pView;
00199 FL_ListType m_List_Type;
00200 UT_uint32 m_iID;
00201 UT_uint32 m_iParentID;
00202 UT_uint32 m_iLevel;
00203 UT_uint32 m_iStartValue;
00204 UT_uint16 m_iAsciiOffset;
00205 bool m_bUpdatingItems;
00206 bool m_bDirty;
00207 UT_sint32 m_ioffset;
00208 gchar m_pszDecimal[80];
00209 gchar m_pszDelim[80];
00210 gchar m_pszIndent[80];
00211 bool m_bWordMultiStyle;
00212 pf_Frag_Strux* m_pParentItem;
00213 };
00214
00215 #endif