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 ************************************************************************/
60 /*************************************************************************
63 ************************************************************************/
64 #include "lwpfootnote.hxx"
65 #include "lwpstory.hxx"
66 #include "xfilter/xffootnote.hxx"
67 #include "xfilter/xfendnote.hxx"
68 #include "xfilter/xffootnoteconfig.hxx"
69 #include "xfilter/xfendnoteconfig.hxx"
70 #include "xfilter/xfstylemanager.hxx"
71 #include "xfilter/xftextspan.hxx"
72 #include "lwppara.hxx"
74 #include "lwpfnlayout.hxx"
75 #include "lwpglobalmgr.hxx"
77 LwpFribFootnote::LwpFribFootnote(LwpPara
* pPara
):LwpFrib(pPara
)
82 * @descr read footnote frib information
84 void LwpFribFootnote::Read(LwpObjectStream
* pObjStrm
, sal_uInt16
/*len*/)
86 m_Footnote
.ReadIndexed(pObjStrm
);
90 * @descr Register footnote style by calling LwpFootnote::RegisterStyle()
92 void LwpFribFootnote::RegisterNewStyle()
94 LwpFootnote
* pFootnote
= GetFootnote();
97 //register footnote number font style
98 LwpFrib::RegisterStyle(m_pPara
->GetFoundry());
99 //register footnote content style
100 pFootnote
->SetFoundry(m_pPara
->GetFoundry());
101 pFootnote
->RegisterStyle();
106 * @descr Parse footnote by calling LwpFootnote::XFConvert()
108 void LwpFribFootnote::XFConvert(XFContentContainer
* pCont
)
110 LwpFootnote
* pFootnote
= GetFootnote();
113 XFContentContainer
* pContent
= NULL
;
114 if(pFootnote
->GetType() == FN_FOOTNOTE
)
116 pContent
= new XFFootNote();
120 pContent
= new XFEndNote();
122 pFootnote
->XFConvert(pContent
);
125 //set footnote number font style
126 XFTextSpan
*pSpan
= new XFTextSpan();
127 pSpan
->SetStyleName(GetStyleName());
128 //add the xffootnote into the content container
129 pSpan
->Add(pContent
);
134 pCont
->Add(pContent
);
140 * @descr Get foonote object
142 LwpFootnote
* LwpFribFootnote::GetFootnote()
144 return dynamic_cast<LwpFootnote
*>(m_Footnote
.obj());
148 LwpFootnote::LwpFootnote(LwpObjectHeader
&objHdr
, LwpSvStream
*pStrm
)
149 : LwpOrderedObject(objHdr
, pStrm
)
153 LwpFootnote::~LwpFootnote()
159 * @descr Read foonote object
161 void LwpFootnote::Read()
163 LwpOrderedObject::Read();
164 m_nType
= m_pObjStrm
->QuickReaduInt16();
165 m_nRow
= m_pObjStrm
->QuickReaduInt16();
166 m_Content
.ReadIndexed(m_pObjStrm
);
167 m_pObjStrm
->SkipExtra();
171 * @descr Register footnote style
173 void LwpFootnote::RegisterStyle()
175 //Only register footnote contents style,
176 //Endnote contents style registers in LwpEnSuperTableLayout::RegisterStyle
177 if(m_nType
== FN_FOOTNOTE
)
179 LwpContent
* pContent
= FindFootnoteContent();
182 pContent
->SetFoundry(m_pFoundry
);
183 pContent
->RegisterStyle();
189 * @descr Parse footnote
191 void LwpFootnote::XFConvert(XFContentContainer
* pCont
)
193 LwpContent
* pContent
= FindFootnoteContent();
196 pContent
->XFConvert(pCont
);
201 * @descr Get endnote cell layout which contains current endnote content
203 LwpCellLayout
* LwpFootnote::GetCellLayout()
205 LwpEnSuperTableLayout
* pEnSuperLayout
= FindFootnoteTableLayout();
208 LwpTableLayout
* pTableLayout
= static_cast<LwpTableLayout
*>(pEnSuperLayout
->GetMainTableLayout());
211 LwpRowLayout
* pRowLayout
= pTableLayout
->GetRowLayout(m_nRow
);
214 return dynamic_cast<LwpCellLayout
*>(pRowLayout
->GetChildHead()->obj());
222 * @descr Get division which footnote table contains current footnote content, copy from lwp source code
224 LwpDocument
* LwpFootnote::GetFootnoteTableDivision()
229 LwpDocument
* pPrev
=NULL
;
230 LwpDocument
* pDivision
= NULL
;
231 LwpDocument
* pFootnoteDivision
=NULL
;
233 // Make sure the footnote does belong to some division
234 // The division might not have a DivisionInfo if it's being Destruct()ed
235 pPrev
= m_pFoundry
->GetDocument();
236 pFootnoteDivision
= pPrev
;
237 if (!pPrev
|| pPrev
->GetDivInfoID()->IsNull())
244 // Footnotes always use the source division
245 return pFootnoteDivision
;
249 // Start with the footnote's division
253 case FN_DIVISION_SEPARATE
:
255 // It had better be the next division
256 pDivision
= pPrev
->GetNextDivision();
259 case FN_DIVISIONGROUP
:
260 case FN_DIVISIONGROUP_SEPARATE
:
262 pDivision
= pPrev
->GetLastInGroupWithContents();
267 case FN_DOCUMENT_SEPARATE
:
269 pDivision
= pFootnoteDivision
->GetRootDocument();
271 pDivision
= pDivision
->GetLastDivisionWithContents();
278 // Make sure we're using the proper endnote division, if it's separate
279 if (m_nType
& FN_MASK_SEPARATE
)
280 pDivision
= GetEndnoteDivision(pDivision
);
281 // Don't use a division that's specifically for endnotes
286 if (pDivision
->GetEndnoteType() == FN_DONTCARE
)
288 if (m_nType
== FN_DIVISIONGROUP
)
289 pDivision
= pDivision
->GetPreviousInGroup();
291 pDivision
= pDivision
->GetPreviousDivisionWithContents();
300 * @descr Get division which endnote table contains current endnote content, copy from lwp source code
302 LwpDocument
* LwpFootnote::GetEndnoteDivision(LwpDocument
* pPossible
)
304 LwpDocument
* pDivision
= pPossible
;
307 // In case we have multiple endnote divisions, walk backwards until
311 // Do we already have the right division?
312 nDivType
= pDivision
->GetEndnoteType();
313 if (nDivType
== m_nType
)
315 // When we hit the first non-endnote division, stop looking.
317 if (nDivType
== FN_DONTCARE
)
319 pDivision
= pDivision
->GetPreviousDivision();
325 * @descr Get footnote table class name
327 OUString
LwpFootnote::GetTableClass()
329 OUString strClassName
;
330 switch (GetType() & FN_MASK_BASE
)
332 case FN_BASE_FOOTNOTE
:
334 strClassName
= A2OUSTR(STR_DivisionFootnote
);
337 case FN_BASE_DOCUMENT
:
339 strClassName
= A2OUSTR(STR_DocumentEndnote
);
342 case FN_BASE_DIVISION
:
344 strClassName
= A2OUSTR(STR_DivisionEndnote
);
347 case FN_BASE_DIVISIONGROUP
:
349 strClassName
= A2OUSTR(STR_DivisionGroupEndnote
);
357 * @descr Find footnote tablelayout, copy from lwp source code
359 LwpEnSuperTableLayout
* LwpFootnote::FindFootnoteTableLayout()
361 LwpDocument
* pDivision
= GetFootnoteTableDivision();
365 LwpFoundry
* pFoundry
= pDivision
->GetFoundry();
366 OUString strClassName
= GetTableClass();
367 if(strClassName
.isEmpty() )
370 LwpContent
* pContent
= NULL
;
372 while ((pContent
= pFoundry
->EnumContents(pContent
)) != NULL
)
373 if (pContent
->IsTable() && (strClassName
.equals(pContent
->GetClassName())) &&
374 pContent
->IsActive() && pContent
->GetLayout(NULL
))
377 return (LwpEnSuperTableLayout
*)
378 ((LwpTable
*)pContent
)->GetSuperTableLayout();
385 * @descr Find footnote contents
387 LwpContent
* LwpFootnote::FindFootnoteContent()
389 LwpContent
* pContent
= dynamic_cast<LwpContent
*>(m_Content
.obj());
390 //if the content has layout, the content has footnote contents;
391 //or looking for the celllayout and return the footnote contents.
392 if(pContent
&& pContent
->GetLayout(NULL
))
395 LwpCellLayout
* pCellLayout
= GetCellLayout();
398 pContent
= dynamic_cast<LwpContent
*>(pCellLayout
->GetContent()->obj());
404 LwpFootnoteTable::LwpFootnoteTable(LwpObjectHeader
&objHdr
, LwpSvStream
*pStrm
)
405 : LwpTable(objHdr
, pStrm
)
409 void LwpFootnoteTable::Read()
412 m_pObjStrm
->SkipExtra();
416 * @descr Read footnote number options information
418 void LwpFootnoteNumberOptions::Read(LwpObjectStream
*pObjStrm
)
420 m_nFlag
= pObjStrm
->QuickReaduInt16();
421 m_nStartingNumber
= pObjStrm
->QuickReaduInt16();
422 m_LeadingText
.Read(pObjStrm
);
423 m_TrailingText
.Read(pObjStrm
);
424 pObjStrm
->SkipExtra();
428 * @descr Read footnote separator options information
430 void LwpFootnoteSeparatorOptions::Read(LwpObjectStream
*pObjStrm
)
432 m_nFlag
= pObjStrm
->QuickReaduInt16();
433 m_nLength
= pObjStrm
->QuickReaduInt32();
434 m_nIndent
= pObjStrm
->QuickReaduInt32();
435 m_nAbove
= pObjStrm
->QuickReaduInt32();
436 m_nBelow
= pObjStrm
->QuickReaduInt32();
437 m_BorderStuff
.Read(pObjStrm
);
438 pObjStrm
->SkipExtra();
442 LwpFootnoteOptions::LwpFootnoteOptions(LwpObjectHeader
&objHdr
, LwpSvStream
*pStrm
)
443 : LwpObject(objHdr
, pStrm
)
447 LwpFootnoteOptions::~LwpFootnoteOptions()
453 * @descr Register footnote options object
455 void LwpFootnoteOptions::Read()
457 m_nFlag
= m_pObjStrm
->QuickReaduInt16();
458 m_FootnoteNumbering
.Read(m_pObjStrm
);
459 m_EndnoteDivisionNumbering
.Read(m_pObjStrm
);
460 m_EndnoteDivisionGroupNumbering
.Read(m_pObjStrm
);
461 m_EndnoteDocNumbering
.Read(m_pObjStrm
);
462 m_FootnoteSeparator
.Read(m_pObjStrm
);
463 m_FootnoteContinuedSeparator
.Read(m_pObjStrm
);
464 m_ContinuedOnMessage
.Read(m_pObjStrm
);
465 m_ContinuedFromMessage
.Read(m_pObjStrm
);
466 m_pObjStrm
->SkipExtra();
470 * @descr Register footnote options style
472 void LwpFootnoteOptions::RegisterStyle()
474 RegisterFootnoteStyle();
475 RegisterEndnoteStyle();
479 * @descr Register footnote configuration information
481 void LwpFootnoteOptions::RegisterFootnoteStyle()
483 XFFootnoteConfig
* pFootnoteConfig
= new XFFootnoteConfig();
484 pFootnoteConfig
->SetStartValue(m_FootnoteNumbering
.GetStartingNumber() -1);
485 pFootnoteConfig
->SetNumPrefix(m_FootnoteNumbering
.GetLeadingText());
486 pFootnoteConfig
->SetNumSuffix(m_FootnoteNumbering
.GetTrailingText());
487 if(m_FootnoteNumbering
.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE
)
489 pFootnoteConfig
->SetRestartOnPage();
491 if(GetContinuedFrom())
493 pFootnoteConfig
->SetMessageFrom(GetContinuedFromMessage());
497 pFootnoteConfig
->SetMessageOn(GetContinuedOnMessage());
500 pFootnoteConfig
->SetMasterPage( m_strMasterPage
);
501 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
502 pXFStyleManager
->SetFootnoteConfig(pFootnoteConfig
);
507 * @descr Register endnote configuration information
509 void LwpFootnoteOptions::RegisterEndnoteStyle()
511 XFEndnoteConfig
* pEndnoteConfig
= new XFEndnoteConfig();
512 pEndnoteConfig
->SetStartValue(m_EndnoteDocNumbering
.GetStartingNumber() -1);
513 OUString message
= m_EndnoteDocNumbering
.GetLeadingText();
514 if(message
.isEmpty())
516 message
= A2OUSTR("[");//default prefix
518 pEndnoteConfig
->SetNumPrefix(message
);
519 message
= m_EndnoteDocNumbering
.GetTrailingText();
520 if(message
.isEmpty())
522 message
= A2OUSTR("]");//default suffix
524 pEndnoteConfig
->SetNumSuffix(message
);
525 if(m_EndnoteDocNumbering
.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE
)
527 pEndnoteConfig
->SetRestartOnPage();
530 pEndnoteConfig
->SetMasterPage( m_strMasterPage
);
532 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
533 pXFStyleManager
->SetEndnoteConfig(pEndnoteConfig
);
538 * @descr Get continue on message
540 OUString
LwpFootnoteOptions::GetContinuedOnMessage()
542 if(m_ContinuedOnMessage
.HasValue())
544 return m_ContinuedOnMessage
.str();
546 // else reture defauls message
547 return A2OUSTR(STRID_FOOTCONTINUEDON
);
551 * @descr Get continue from message
553 OUString
LwpFootnoteOptions::GetContinuedFromMessage()
555 if(m_ContinuedFromMessage
.HasValue())
557 return m_ContinuedFromMessage
.str();
559 // else reture defauls message
560 return A2OUSTR(STRID_FOOTCONTINUEDFROM
);
563 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */