00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ 00002 00003 /* AbiSource 00004 * 00005 * Copyright (C) 2007 Philippe Milot <PhilMilot@gmail.com> 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation; either version 2 00010 * of the License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00020 * 02110-1301 USA. 00021 */ 00022 00023 #ifndef _OXML_SECTION_H_ 00024 #define _OXML_SECTION_H_ 00025 00026 // Internal includes 00027 #include <OXML_Types.h> 00028 #include <OXML_ObjectWithAttrProp.h> 00029 #include <OXML_Element.h> 00030 00031 // AbiWord includes 00032 #include <ut_types.h> 00033 #include <pd_Document.h> 00034 00035 // External includes 00036 #include <string> 00037 #include <vector> 00038 #include <map> 00039 #include <memory> 00040 00041 class OXML_Section; 00042 class OXML_Element_Paragraph; 00043 class IE_Exp_OpenXML; 00044 00045 typedef std::shared_ptr<OXML_Section> OXML_SharedSection; 00046 00047 /* \class OXML_Section 00048 * \brief This class represents a single section in the OpenXML data model. 00049 * It holds references to all its content, as well as references 00050 * to all its corresponding headers and footers. 00051 */ 00052 class OXML_Section : public OXML_ObjectWithAttrProp 00053 { 00054 public: 00055 OXML_Section(); 00056 OXML_Section(const std::string & id); 00057 virtual ~OXML_Section(); 00058 00059 const std::string & getId() const 00060 { return m_id; } 00061 OXML_SectionBreakType getBreakType() const 00062 { return m_breakType; } 00063 void setBreakType(OXML_SectionBreakType br) 00064 { m_breakType = br; } 00065 00066 const char * getHeaderId(OXML_HeaderFooterType type) const 00067 { return m_headerIds[type]; } 00068 const char * getFooterId(OXML_HeaderFooterType type) const 00069 { return m_footerIds[type]; } 00070 void setHeaderId(const char * id, OXML_HeaderFooterType type) 00071 { m_headerIds[type] = g_strdup(id); } 00072 void setFooterId(const char * id, OXML_HeaderFooterType type) 00073 { m_footerIds[type] = g_strdup(id); } 00074 00075 bool operator ==(const std::string & id); 00076 friend bool operator ==(const OXML_SharedSection& lhs, const std::string & id); 00077 00078 OXML_SharedElement getElement(const std::string & id); 00079 UT_Error appendElement(OXML_SharedElement obj); 00080 inline void setChildren(OXML_ElementVector c) { m_children = c; } 00081 UT_Error clearChildren(); 00082 00084 00087 UT_Error serialize(IE_Exp_OpenXML* exporter); 00088 UT_Error serializeProperties(IE_Exp_OpenXML* exporter, OXML_Element_Paragraph* pParagraph); 00089 void applyDocumentProperties(); 00090 00091 UT_Error serializeHeader(IE_Exp_OpenXML* exporter); 00092 UT_Error serializeFooter(IE_Exp_OpenXML* exporter); 00093 UT_Error serializeFootnote(IE_Exp_OpenXML* exporter); 00094 UT_Error serializeEndnote(IE_Exp_OpenXML* exporter); 00095 00097 00100 UT_Error addToPT(PD_Document * pDocument); 00101 UT_Error addToPTAsHdrFtr(PD_Document * pDocument); 00102 UT_Error addToPTAsFootnote(PD_Document * pDocument); 00103 UT_Error addToPTAsEndnote(PD_Document * pDocument); 00104 00105 void setTarget(int target); 00106 bool hasFirstPageHdrFtr() const; 00107 bool hasEvenPageHdrFtr() const; 00108 void setHandledHdrFtr(bool val) 00109 { m_handledHdrFtr = val; } 00110 bool getHandledHdrFtr() const 00111 { return m_handledHdrFtr; } 00112 00113 UT_Error setPageMargins(const std::string & top, const std::string & left, const std::string & right, const std::string & bottom); 00114 00115 private: 00116 std::string m_id; 00117 OXML_SectionBreakType m_breakType; 00118 OXML_ElementVector m_children; 00119 OXML_Element_Paragraph* m_lastParagraph; 00120 char * m_headerIds[3]; 00121 char * m_footerIds[3]; 00122 int m_target; 00123 bool m_handledHdrFtr; 00124 00125 UT_Error _setReferenceIds(); 00126 }; 00127 00128 00129 typedef std::vector< OXML_SharedSection > OXML_SectionVector; 00130 typedef std::map<std::string, OXML_SharedSection > OXML_SectionMap; 00131 00132 inline bool operator ==(const OXML_SharedSection& lhs, const std::string & id) 00133 { 00134 return (*lhs) == id; 00135 } 00136 00137 #endif //_OXML_SECTION_H_ 00138