1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
59 /*************************************************************************
62 ************************************************************************/
63 #include "lwpfootnote.hxx"
64 #include "lwpstory.hxx"
65 #include "xfilter/xffootnote.hxx"
66 #include "xfilter/xfendnote.hxx"
67 #include "xfilter/xffootnoteconfig.hxx"
68 #include "xfilter/xfendnoteconfig.hxx"
69 #include "xfilter/xfstylemanager.hxx"
70 #include "xfilter/xftextspan.hxx"
71 #include "lwppara.hxx"
73 #include "lwpfnlayout.hxx"
74 #include "lwpglobalmgr.hxx"
76 LwpFribFootnote::LwpFribFootnote(LwpPara
* pPara
):LwpFrib(pPara
)
81 * @descr read footnote frib information
83 void LwpFribFootnote::Read(LwpObjectStream
*pObjStrm
, sal_uInt16 len
)
85 m_Footnote
.ReadIndexed(pObjStrm
);
89 * @descr Register footnote style by calling LwpFootnote::RegisterStyle()
91 void LwpFribFootnote::RegisterStyle()
93 LwpFootnote
* pFootnote
= GetFootnote();
96 //register footnote number font style
97 LwpFrib::RegisterStyle(m_pPara
->GetFoundry());
98 //register footnote content style
99 pFootnote
->SetFoundry(m_pPara
->GetFoundry());
100 pFootnote
->RegisterStyle();
105 * @descr Parse footnote by calling LwpFootnote::XFConvert()
107 void LwpFribFootnote::XFConvert(XFContentContainer
* pCont
)
109 LwpFootnote
* pFootnote
= GetFootnote();
112 XFContentContainer
* pContent
= NULL
;
113 if(pFootnote
->GetType() == FN_FOOTNOTE
)
115 pContent
= new XFFootNote();
119 pContent
= new XFEndNote();
121 pFootnote
->XFConvert(pContent
);
124 //set footnote number font style
125 XFTextSpan
*pSpan
= new XFTextSpan();
126 pSpan
->SetStyleName(GetStyleName());
127 //add the xffootnote into the content container
128 pSpan
->Add(pContent
);
133 pCont
->Add(pContent
);
139 * @descr Get foonote object
141 LwpFootnote
* LwpFribFootnote::GetFootnote()
143 return static_cast<LwpFootnote
*>(m_Footnote
.obj());
147 LwpFootnote::LwpFootnote(LwpObjectHeader
&objHdr
, LwpSvStream
*pStrm
)
148 : LwpOrderedObject(objHdr
, pStrm
)
152 LwpFootnote::~LwpFootnote()
158 * @descr Read foonote object
160 void LwpFootnote::Read()
162 LwpOrderedObject::Read();
163 m_pObjStrm
->QuickRead(&m_nType
, sizeof(m_nType
));
164 m_pObjStrm
->QuickRead(&m_nRow
, sizeof(m_nRow
));
165 m_Content
.ReadIndexed(m_pObjStrm
);
166 m_pObjStrm
->SkipExtra();
170 * @descr Register footnote style
172 void LwpFootnote::RegisterStyle()
174 //Only register footnote contents style,
175 //Endnote contents style registers in LwpEnSuperTableLayout::RegisterStyle
176 if(m_nType
== FN_FOOTNOTE
)
178 LwpContent
* pContent
= FindFootnoteContent();
181 pContent
->SetFoundry(m_pFoundry
);
182 pContent
->RegisterStyle();
188 * @descr Parse footnote
190 void LwpFootnote::XFConvert(XFContentContainer
* pCont
)
192 LwpContent
* pContent
= FindFootnoteContent();
195 pContent
->XFConvert(pCont
);
200 * @descr Get endnote cell layout which contains current endnote content
202 LwpCellLayout
* LwpFootnote::GetCellLayout()
204 LwpEnSuperTableLayout
* pEnSuperLayout
= FindFootnoteTableLayout();
207 LwpTableLayout
* pTableLayout
= static_cast<LwpTableLayout
*>(pEnSuperLayout
->GetMainTableLayout());
210 LwpRowLayout
* pRowLayout
= pTableLayout
->GetRowLayout(m_nRow
);
213 return static_cast<LwpCellLayout
*>(pRowLayout
->GetChildHead()->obj());
220 * @descr Get endnote supertable layout which contains current endnote content, not used now
222 LwpEnSuperTableLayout
* LwpFootnote::GetEnSuperTableLayout()
224 LwpDocument
* pDivision
= GetFootnoteTableDivision();
226 return static_cast<LwpEnSuperTableLayout
*>(pDivision
->GetEnSuperTableLayout());
231 * @descr Get division which footnote table contains current footnote content, copy from lwp source code
233 LwpDocument
* LwpFootnote::GetFootnoteTableDivision()
238 LwpDocument
* pPrev
=NULL
;
239 LwpDocument
* pDivision
= NULL
;
240 LwpDocument
* pFootnoteDivision
=NULL
;
242 // Make sure the footnote does belong to some division
243 // The division might not have a DivisionInfo if it's being Destruct()ed
244 pPrev
= m_pFoundry
->GetDocument();
245 pFootnoteDivision
= pPrev
;
246 if (!pPrev
|| pPrev
->GetDivInfoID()->IsNull())
253 // Footnotes always use the source division
254 return pFootnoteDivision
;
258 // Start with the footnote's division
262 case FN_DIVISION_SEPARATE
:
264 // It had better be the next division
265 pDivision
= pPrev
->GetNextDivision();
268 case FN_DIVISIONGROUP
:
269 case FN_DIVISIONGROUP_SEPARATE
:
271 pDivision
= pPrev
->GetLastInGroupWithContents();
276 case FN_DOCUMENT_SEPARATE
:
278 pDivision
= pFootnoteDivision
->GetRootDocument();
280 pDivision
= pDivision
->GetLastDivisionWithContents();
287 // Make sure we're using the proper endnote division, if it's separate
288 if (m_nType
& FN_MASK_SEPARATE
)
289 pDivision
= GetEndnoteDivision(pDivision
);
290 // Don't use a division that's specifically for endnotes
295 if (pDivision
->GetEndnoteType() == FN_DONTCARE
)
297 if (m_nType
== FN_DIVISIONGROUP
)
298 pDivision
= pDivision
->GetPreviousInGroup();
300 pDivision
= pDivision
->GetPreviousDivisionWithContents();
309 * @descr Get division which endnote table contains current endnote content, copy from lwp source code
311 LwpDocument
* LwpFootnote::GetEndnoteDivision(LwpDocument
* pPossible
)
313 LwpDocument
* pDivision
= pPossible
;
316 // In case we have multiple endnote divisions, walk backwards until
320 // Do we already have the right division?
321 nDivType
= pDivision
->GetEndnoteType();
322 if (nDivType
== m_nType
)
324 // When we hit the first non-endnote division, stop looking.
326 if (nDivType
== FN_DONTCARE
)
328 pDivision
= pDivision
->GetPreviousDivision();
334 * @descr Get footnote table class name
336 OUString
LwpFootnote::GetTableClass()
338 OUString strClassName
;
339 switch (GetType() & FN_MASK_BASE
)
341 case FN_BASE_FOOTNOTE
:
343 strClassName
= A2OUSTR(STR_DivisionFootnote
);
346 case FN_BASE_DOCUMENT
:
348 strClassName
= A2OUSTR(STR_DocumentEndnote
);
351 case FN_BASE_DIVISION
:
353 strClassName
= A2OUSTR(STR_DivisionEndnote
);
356 case FN_BASE_DIVISIONGROUP
:
358 strClassName
= A2OUSTR(STR_DivisionGroupEndnote
);
366 * @descr Find footnote tablelayout, copy from lwp source code
368 LwpEnSuperTableLayout
* LwpFootnote::FindFootnoteTableLayout()
370 LwpDocument
* pDivision
= GetFootnoteTableDivision();
374 LwpFoundry
* pFoundry
= pDivision
->GetFoundry();
375 OUString strClassName
= GetTableClass();
376 if(strClassName
.getLength() ==0 )
379 LwpContent
* pContent
= NULL
;
381 while ((pContent
= pFoundry
->EnumContents(pContent
)) != NULL
)
382 if (pContent
->IsTable() && (strClassName
.equals(pContent
->GetClassName())) &&
383 pContent
->IsActive() && pContent
->GetLayout(NULL
))
386 return (LwpEnSuperTableLayout
*)
387 ((LwpTable
*)pContent
)->GetSuperTableLayout();
394 * @descr Find footnote table, not used now
396 LwpTable
* LwpFootnote::FindFootnoteTable()
398 LwpEnSuperTableLayout
* pLayout
= FindFootnoteTableLayout();
399 //if (!ShouldBeInTable(Footnote)) return NULL;
400 return GetFootnoteTable(pLayout
);
404 * @descr Find footnote table, not used now
406 LwpTable
* LwpFootnote::GetFootnoteTable(LwpEnSuperTableLayout
* pLayout
)
410 LwpEndnoteLayout
* pEndnoteLayout
= static_cast<LwpEndnoteLayout
*>(pLayout
->GetMainTableLayout());
412 return static_cast<LwpTable
*>(pEndnoteLayout
->GetContent()->obj());
418 * @descr Find footnote contents
420 LwpContent
* LwpFootnote::FindFootnoteContent()
422 LwpContent
* pContent
= static_cast<LwpContent
*>(m_Content
.obj());
423 //if the content has layout, the content has footnote contents;
424 //or looking for the celllayout and return the footnote contents.
425 if(pContent
&& pContent
->GetLayout(NULL
))
428 LwpCellLayout
* pCellLayout
= GetCellLayout();
431 pContent
=static_cast<LwpContent
*>(pCellLayout
->GetContent()->obj());
437 LwpFootnoteTable::LwpFootnoteTable(LwpObjectHeader
&objHdr
, LwpSvStream
*pStrm
)
438 : LwpTable(objHdr
, pStrm
)
442 void LwpFootnoteTable::Read()
445 m_pObjStrm
->SkipExtra();
449 * @descr Read footnote number options information
451 void LwpFootnoteNumberOptions::Read(LwpObjectStream
*pObjStrm
)
453 pObjStrm
->QuickRead(&m_nFlag
, sizeof(m_nFlag
));
454 pObjStrm
->QuickRead(&m_nStartingNumber
, sizeof(m_nStartingNumber
));
455 m_LeadingText
.Read(pObjStrm
);
456 m_TrailingText
.Read(pObjStrm
);
457 pObjStrm
->SkipExtra();
461 * @descr Read footnote seperator options information
463 void LwpFootnoteSeparatorOptions::Read(LwpObjectStream
*pObjStrm
)
465 pObjStrm
->QuickRead(&m_nFlag
, sizeof(m_nFlag
));
466 pObjStrm
->QuickRead(&m_nLength
, sizeof(m_nLength
));
467 pObjStrm
->QuickRead(&m_nIndent
, sizeof(m_nIndent
));
468 pObjStrm
->QuickRead(&m_nAbove
, sizeof(m_nAbove
));
469 pObjStrm
->QuickRead(&m_nBelow
, sizeof(m_nBelow
));
470 m_BorderStuff
.Read(pObjStrm
);
471 pObjStrm
->SkipExtra();
476 LwpFootnoteOptions::LwpFootnoteOptions(LwpObjectHeader
&objHdr
, LwpSvStream
*pStrm
)
477 : LwpObject(objHdr
, pStrm
)
481 LwpFootnoteOptions::~LwpFootnoteOptions()
487 * @descr Register footnote options object
489 void LwpFootnoteOptions::Read()
491 m_pObjStrm
->QuickRead(&m_nFlag
, sizeof(m_nFlag
));
492 m_FootnoteNumbering
.Read(m_pObjStrm
);
493 m_EndnoteDivisionNumbering
.Read(m_pObjStrm
);
494 m_EndnoteDivisionGroupNumbering
.Read(m_pObjStrm
);
495 m_EndnoteDocNumbering
.Read(m_pObjStrm
);
496 m_FootnoteSeparator
.Read(m_pObjStrm
);
497 m_FootnoteContinuedSeparator
.Read(m_pObjStrm
);
498 m_ContinuedOnMessage
.Read(m_pObjStrm
);
499 m_ContinuedFromMessage
.Read(m_pObjStrm
);
500 m_pObjStrm
->SkipExtra();
504 * @descr Register footnote options style
506 void LwpFootnoteOptions::RegisterStyle()
508 RegisterFootnoteStyle();
509 RegisterEndnoteStyle();
513 * @descr Register footnote configuration information
515 void LwpFootnoteOptions::RegisterFootnoteStyle()
517 XFFootnoteConfig
* pFootnoteConfig
= new XFFootnoteConfig();
518 pFootnoteConfig
->SetStartValue(m_FootnoteNumbering
.GetStartingNumber() -1);
519 pFootnoteConfig
->SetNumPrefix(m_FootnoteNumbering
.GetLeadingText());
520 pFootnoteConfig
->SetNumSuffix(m_FootnoteNumbering
.GetTrailingText());
521 if(m_FootnoteNumbering
.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE
)
523 pFootnoteConfig
->SetRestartOnPage();
525 if(GetContinuedFrom())
527 pFootnoteConfig
->SetMessageFrom(GetContinuedFromMessage());
531 pFootnoteConfig
->SetMessageOn(GetContinuedOnMessage());
534 pFootnoteConfig
->SetMasterPage( m_strMasterPage
);
535 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
536 pXFStyleManager
->SetFootnoteConfig(pFootnoteConfig
);
541 * @descr Register endnote configuration information
543 void LwpFootnoteOptions::RegisterEndnoteStyle()
545 XFEndnoteConfig
* pEndnoteConfig
= new XFEndnoteConfig();
546 pEndnoteConfig
->SetStartValue(m_EndnoteDocNumbering
.GetStartingNumber() -1);
547 OUString message
= m_EndnoteDocNumbering
.GetLeadingText();
548 if(message
.getLength() == 0)
550 message
= A2OUSTR("[");//default prefix
552 pEndnoteConfig
->SetNumPrefix(message
);
553 message
= m_EndnoteDocNumbering
.GetTrailingText();
554 if(message
.getLength() == 0)
556 message
= A2OUSTR("]");//default suffix
558 pEndnoteConfig
->SetNumSuffix(message
);
559 if(m_EndnoteDocNumbering
.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE
)
561 pEndnoteConfig
->SetRestartOnPage();
564 pEndnoteConfig
->SetMasterPage( m_strMasterPage
);
566 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
567 pXFStyleManager
->SetEndnoteConfig(pEndnoteConfig
);
572 * @descr Get continue on message
574 OUString
LwpFootnoteOptions::GetContinuedOnMessage()
576 if(m_ContinuedOnMessage
.HasValue())
578 return m_ContinuedOnMessage
.str();
580 // else reture defauls message
581 return A2OUSTR(STRID_FOOTCONTINUEDON
);
585 * @descr Get continue from message
587 OUString
LwpFootnoteOptions::GetContinuedFromMessage()
589 if(m_ContinuedFromMessage
.HasValue())
591 return m_ContinuedFromMessage
.str();
593 // else reture defauls message
594 return A2OUSTR(STRID_FOOTCONTINUEDFROM
);