1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
58 #include "lwpfootnote.hxx"
59 #include <xfilter/xffootnote.hxx>
60 #include <xfilter/xfendnote.hxx>
61 #include <xfilter/xffootnoteconfig.hxx>
62 #include <xfilter/xfendnoteconfig.hxx>
63 #include <xfilter/xfstylemanager.hxx>
64 #include <xfilter/xftextspan.hxx>
65 #include "lwppara.hxx"
67 #include "lwpfnlayout.hxx"
68 #include <lwpglobalmgr.hxx>
70 LwpFribFootnote::LwpFribFootnote(LwpPara
* pPara
)
76 * @descr read footnote frib information
78 void LwpFribFootnote::Read(LwpObjectStream
* pObjStrm
, sal_uInt16
/*len*/)
80 m_Footnote
.ReadIndexed(pObjStrm
);
84 * @descr Register footnote style by calling LwpFootnote::RegisterStyle()
86 void LwpFribFootnote::RegisterNewStyle()
88 LwpFootnote
* pFootnote
= GetFootnote();
91 //register footnote number font style
92 LwpFrib::RegisterStyle(m_pPara
->GetFoundry());
93 //register footnote content style
94 pFootnote
->SetFoundry(m_pPara
->GetFoundry());
95 pFootnote
->RegisterStyle();
100 * @descr Parse footnote by calling LwpFootnote::XFConvert()
102 void LwpFribFootnote::XFConvert(XFContentContainer
* pCont
)
104 LwpFootnote
* pFootnote
= GetFootnote();
108 rtl::Reference
<XFContentContainer
> xContent
;
109 if (pFootnote
->GetType() == FN_FOOTNOTE
)
111 xContent
.set(new XFFootNote
);
115 xContent
.set(new XFEndNote
);
117 pFootnote
->XFConvert(xContent
.get());
120 //set footnote number font style
121 rtl::Reference
<XFTextSpan
> xSpan(new XFTextSpan
);
122 xSpan
->SetStyleName(GetStyleName());
123 //add the xffootnote into the content container
124 xSpan
->Add(xContent
.get());
125 pCont
->Add(xSpan
.get());
129 pCont
->Add(xContent
.get());
134 * @descr Get foonote object
136 LwpFootnote
* LwpFribFootnote::GetFootnote()
138 return dynamic_cast<LwpFootnote
*>(m_Footnote
.obj().get());
141 LwpFootnote::LwpFootnote(LwpObjectHeader
const& objHdr
, LwpSvStream
* pStrm
)
142 : LwpOrderedObject(objHdr
, pStrm
)
148 LwpFootnote::~LwpFootnote() {}
151 * @descr Read foonote object
153 void LwpFootnote::Read()
155 LwpOrderedObject::Read();
156 m_nType
= m_pObjStrm
->QuickReaduInt16();
157 m_nRow
= m_pObjStrm
->QuickReaduInt16();
158 m_Content
.ReadIndexed(m_pObjStrm
.get());
159 m_pObjStrm
->SkipExtra();
163 * @descr Register footnote style
165 void LwpFootnote::RegisterStyle()
167 //Only register footnote contents style,
168 //Endnote contents style registers in LwpEnSuperTableLayout::RegisterStyle
169 if (m_nType
== FN_FOOTNOTE
)
171 LwpContent
* pContent
= FindFootnoteContent();
174 pContent
->SetFoundry(m_pFoundry
);
175 pContent
->DoRegisterStyle();
181 * @descr Parse footnote
183 void LwpFootnote::XFConvert(XFContentContainer
* pCont
)
185 LwpContent
* pContent
= FindFootnoteContent();
188 pContent
->DoXFConvert(pCont
);
193 * @descr Get endnote cell layout which contains current endnote content
195 LwpCellLayout
* LwpFootnote::GetCellLayout()
197 LwpEnSuperTableLayout
* pEnSuperLayout
= FindFootnoteTableLayout();
200 LwpTableLayout
* pTableLayout
201 = dynamic_cast<LwpTableLayout
*>(pEnSuperLayout
->GetMainTableLayout());
204 LwpRowLayout
* pRowLayout
= pTableLayout
->GetRowLayout(m_nRow
);
207 return dynamic_cast<LwpCellLayout
*>(pRowLayout
->GetChildHead().obj().get());
215 * @descr Get division which footnote table contains current footnote content, copy from lwp source code
217 LwpDocument
* LwpFootnote::GetFootnoteTableDivision()
222 LwpDocument
* pPrev
= nullptr;
223 LwpDocument
* pDivision
= nullptr;
224 LwpDocument
* pFootnoteDivision
= nullptr;
226 // Make sure the footnote does belong to some division
227 // The division might not have a DivisionInfo if it's being Destruct()ed
228 pPrev
= m_pFoundry
->GetDocument();
229 pFootnoteDivision
= pPrev
;
230 if (!pPrev
|| pPrev
->GetDivInfoID().IsNull())
237 // Footnotes always use the source division
238 return pFootnoteDivision
;
242 // Start with the footnote's division
246 case FN_DIVISION_SEPARATE
:
248 // It had better be the next division
249 pDivision
= pPrev
->GetNextDivision();
252 case FN_DIVISIONGROUP
:
253 case FN_DIVISIONGROUP_SEPARATE
:
255 pDivision
= pPrev
->GetLastInGroupWithContents();
259 case FN_DOCUMENT_SEPARATE
:
261 pDivision
= pFootnoteDivision
->GetRootDocument();
263 pDivision
= pDivision
->GetLastDivisionWithContents();
268 // Make sure we're using the proper endnote division, if it's separate
269 if (m_nType
& FN_MASK_SEPARATE
)
270 pDivision
= GetEndnoteDivision(pDivision
);
271 // Don't use a division that's specifically for endnotes
276 if (pDivision
->GetEndnoteType() == FN_DONTCARE
)
278 if (m_nType
== FN_DIVISIONGROUP
)
279 pDivision
= pDivision
->GetPreviousInGroup();
281 pDivision
= pDivision
->GetPreviousDivisionWithContents();
290 * @descr Get division which endnote table contains current endnote content, copy from lwp source code
292 LwpDocument
* LwpFootnote::GetEndnoteDivision(LwpDocument
* pPossible
)
294 LwpDocument
* pDivision
= pPossible
;
297 // In case we have multiple endnote divisions, walk backwards until
301 // Do we already have the right division?
302 nDivType
= pDivision
->GetEndnoteType();
303 if (nDivType
== m_nType
)
305 // When we hit the first non-endnote division, stop looking.
307 if (nDivType
== FN_DONTCARE
)
309 pDivision
= pDivision
->GetPreviousDivision();
315 * @descr Get footnote table class name
317 OUString
LwpFootnote::GetTableClass() const
319 OUString strClassName
;
320 switch (GetType() & FN_MASK_BASE
)
322 case FN_BASE_FOOTNOTE
:
324 strClassName
= STR_DivisionFootnote
;
327 case FN_BASE_DOCUMENT
:
329 strClassName
= STR_DocumentEndnote
;
332 case FN_BASE_DIVISION
:
334 strClassName
= STR_DivisionEndnote
;
337 case FN_BASE_DIVISIONGROUP
:
339 strClassName
= STR_DivisionGroupEndnote
;
347 * @descr Find footnote tablelayout, copy from lwp source code
349 LwpEnSuperTableLayout
* LwpFootnote::FindFootnoteTableLayout()
351 LwpDocument
* pDivision
= GetFootnoteTableDivision();
355 LwpFoundry
* pFoundry
= pDivision
->GetFoundry();
356 OUString strClassName
= GetTableClass();
357 if (strClassName
.isEmpty())
360 LwpContent
* pContent
= nullptr;
362 while ((pContent
= pFoundry
->EnumContents(pContent
)) != nullptr)
363 if (pContent
->IsTable() && (strClassName
== pContent
->GetClassName())
364 && pContent
->IsActive() && pContent
->GetLayout(nullptr).is())
367 return static_cast<LwpEnSuperTableLayout
*>(
368 static_cast<LwpTable
*>(pContent
)->GetSuperTableLayout());
375 * @descr Find footnote contents
377 LwpContent
* LwpFootnote::FindFootnoteContent()
379 LwpContent
* pContent
= dynamic_cast<LwpContent
*>(m_Content
.obj().get());
380 //if the content has layout, the content has footnote contents;
381 //or looking for the celllayout and return the footnote contents.
382 if (pContent
&& pContent
->GetLayout(nullptr).is())
385 LwpCellLayout
* pCellLayout
= GetCellLayout();
388 pContent
= dynamic_cast<LwpContent
*>(pCellLayout
->GetContent().obj().get());
394 LwpFootnoteTable::LwpFootnoteTable(LwpObjectHeader
const& objHdr
, LwpSvStream
* pStrm
)
395 : LwpTable(objHdr
, pStrm
)
399 void LwpFootnoteTable::Read()
402 m_pObjStrm
->SkipExtra();
406 * @descr Read footnote number options information
408 void LwpFootnoteNumberOptions::Read(LwpObjectStream
* pObjStrm
)
410 m_nFlag
= pObjStrm
->QuickReaduInt16();
411 m_nStartingNumber
= pObjStrm
->QuickReaduInt16();
412 m_LeadingText
.Read(pObjStrm
);
413 m_TrailingText
.Read(pObjStrm
);
414 pObjStrm
->SkipExtra();
418 * @descr Read footnote separator options information
420 void LwpFootnoteSeparatorOptions::Read(LwpObjectStream
* pObjStrm
)
422 m_nFlag
= pObjStrm
->QuickReaduInt16();
423 m_nLength
= pObjStrm
->QuickReaduInt32();
424 m_nIndent
= pObjStrm
->QuickReaduInt32();
425 m_nAbove
= pObjStrm
->QuickReaduInt32();
426 m_nBelow
= pObjStrm
->QuickReaduInt32();
427 m_BorderStuff
.Read(pObjStrm
);
428 pObjStrm
->SkipExtra();
431 LwpFootnoteOptions::LwpFootnoteOptions(LwpObjectHeader
const& objHdr
, LwpSvStream
* pStrm
)
432 : LwpObject(objHdr
, pStrm
)
437 LwpFootnoteOptions::~LwpFootnoteOptions() {}
440 * @descr Register footnote options object
442 void LwpFootnoteOptions::Read()
444 m_nFlag
= m_pObjStrm
->QuickReaduInt16();
445 m_FootnoteNumbering
.Read(m_pObjStrm
.get());
446 m_EndnoteDivisionNumbering
.Read(m_pObjStrm
.get());
447 m_EndnoteDivisionGroupNumbering
.Read(m_pObjStrm
.get());
448 m_EndnoteDocNumbering
.Read(m_pObjStrm
.get());
449 m_FootnoteSeparator
.Read(m_pObjStrm
.get());
450 m_FootnoteContinuedSeparator
.Read(m_pObjStrm
.get());
451 m_ContinuedOnMessage
.Read(m_pObjStrm
.get());
452 m_ContinuedFromMessage
.Read(m_pObjStrm
.get());
453 m_pObjStrm
->SkipExtra();
457 * @descr Register footnote options style
459 void LwpFootnoteOptions::RegisterStyle()
461 RegisterFootnoteStyle();
462 RegisterEndnoteStyle();
466 * @descr Register footnote configuration information
468 void LwpFootnoteOptions::RegisterFootnoteStyle()
470 std::unique_ptr
<XFFootnoteConfig
> xFootnoteConfig(new XFFootnoteConfig
);
471 xFootnoteConfig
->SetStartValue(m_FootnoteNumbering
.GetStartingNumber() - 1);
472 xFootnoteConfig
->SetNumPrefix(m_FootnoteNumbering
.GetLeadingText());
473 xFootnoteConfig
->SetNumSuffix(m_FootnoteNumbering
.GetTrailingText());
474 if (m_FootnoteNumbering
.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE
)
476 xFootnoteConfig
->SetRestartOnPage();
478 if (GetContinuedFrom())
480 xFootnoteConfig
->SetMessageFrom(GetContinuedFromMessage());
482 if (GetContinuedOn())
484 xFootnoteConfig
->SetMessageOn(GetContinuedOnMessage());
487 xFootnoteConfig
->SetMasterPage(m_strMasterPage
);
488 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
489 pXFStyleManager
->SetFootnoteConfig(xFootnoteConfig
.release());
493 * @descr Register endnote configuration information
495 void LwpFootnoteOptions::RegisterEndnoteStyle()
497 std::unique_ptr
<XFEndnoteConfig
> xEndnoteConfig(new XFEndnoteConfig
);
498 xEndnoteConfig
->SetStartValue(m_EndnoteDocNumbering
.GetStartingNumber() - 1);
499 OUString message
= m_EndnoteDocNumbering
.GetLeadingText();
500 if (message
.isEmpty())
502 message
= "["; //default prefix
504 xEndnoteConfig
->SetNumPrefix(message
);
505 message
= m_EndnoteDocNumbering
.GetTrailingText();
506 if (message
.isEmpty())
508 message
= "]"; //default suffix
510 xEndnoteConfig
->SetNumSuffix(message
);
511 if (m_EndnoteDocNumbering
.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE
)
513 xEndnoteConfig
->SetRestartOnPage();
516 xEndnoteConfig
->SetMasterPage(m_strMasterPage
);
518 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
519 pXFStyleManager
->SetEndnoteConfig(xEndnoteConfig
.release());
523 * @descr Get continue on message
525 OUString
LwpFootnoteOptions::GetContinuedOnMessage() const
527 if (m_ContinuedOnMessage
.HasValue())
529 return m_ContinuedOnMessage
.str();
531 // else return default message
532 return STRID_FOOTCONTINUEDON
;
536 * @descr Get continue from message
538 OUString
LwpFootnoteOptions::GetContinuedFromMessage() const
540 if (m_ContinuedFromMessage
.HasValue())
542 return m_ContinuedFromMessage
.str();
544 // else return default message
545 return STRID_FOOTCONTINUEDFROM
;
548 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */