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());
147 LwpFootnote::LwpFootnote(LwpObjectHeader
&objHdr
, LwpSvStream
*pStrm
)
148 : LwpOrderedObject(objHdr
, pStrm
)
154 LwpFootnote::~LwpFootnote()
160 * @descr Read foonote object
162 void LwpFootnote::Read()
164 LwpOrderedObject::Read();
165 m_nType
= m_pObjStrm
->QuickReaduInt16();
166 m_nRow
= m_pObjStrm
->QuickReaduInt16();
167 m_Content
.ReadIndexed(m_pObjStrm
);
168 m_pObjStrm
->SkipExtra();
172 * @descr Register footnote style
174 void LwpFootnote::RegisterStyle()
176 //Only register footnote contents style,
177 //Endnote contents style registers in LwpEnSuperTableLayout::RegisterStyle
178 if(m_nType
== FN_FOOTNOTE
)
180 LwpContent
* pContent
= FindFootnoteContent();
183 pContent
->SetFoundry(m_pFoundry
);
184 pContent
->RegisterStyle();
190 * @descr Parse footnote
192 void LwpFootnote::XFConvert(XFContentContainer
* pCont
)
194 LwpContent
* pContent
= FindFootnoteContent();
197 pContent
->XFConvert(pCont
);
202 * @descr Get endnote cell layout which contains current endnote content
204 LwpCellLayout
* LwpFootnote::GetCellLayout()
206 LwpEnSuperTableLayout
* pEnSuperLayout
= FindFootnoteTableLayout();
209 LwpTableLayout
* pTableLayout
= static_cast<LwpTableLayout
*>(pEnSuperLayout
->GetMainTableLayout());
212 LwpRowLayout
* pRowLayout
= pTableLayout
->GetRowLayout(m_nRow
);
215 return dynamic_cast<LwpCellLayout
*>(pRowLayout
->GetChildHead()->obj());
223 * @descr Get division which footnote table contains current footnote content, copy from lwp source code
225 LwpDocument
* LwpFootnote::GetFootnoteTableDivision()
230 LwpDocument
* pPrev
=NULL
;
231 LwpDocument
* pDivision
= NULL
;
232 LwpDocument
* pFootnoteDivision
=NULL
;
234 // Make sure the footnote does belong to some division
235 // The division might not have a DivisionInfo if it's being Destruct()ed
236 pPrev
= m_pFoundry
->GetDocument();
237 pFootnoteDivision
= pPrev
;
238 if (!pPrev
|| pPrev
->GetDivInfoID()->IsNull())
245 // Footnotes always use the source division
246 return pFootnoteDivision
;
250 // Start with the footnote's division
254 case FN_DIVISION_SEPARATE
:
256 // It had better be the next division
257 pDivision
= pPrev
->GetNextDivision();
260 case FN_DIVISIONGROUP
:
261 case FN_DIVISIONGROUP_SEPARATE
:
263 pDivision
= pPrev
->GetLastInGroupWithContents();
268 case FN_DOCUMENT_SEPARATE
:
270 pDivision
= pFootnoteDivision
->GetRootDocument();
272 pDivision
= pDivision
->GetLastDivisionWithContents();
279 // Make sure we're using the proper endnote division, if it's separate
280 if (m_nType
& FN_MASK_SEPARATE
)
281 pDivision
= GetEndnoteDivision(pDivision
);
282 // Don't use a division that's specifically for endnotes
287 if (pDivision
->GetEndnoteType() == FN_DONTCARE
)
289 if (m_nType
== FN_DIVISIONGROUP
)
290 pDivision
= pDivision
->GetPreviousInGroup();
292 pDivision
= pDivision
->GetPreviousDivisionWithContents();
301 * @descr Get division which endnote table contains current endnote content, copy from lwp source code
303 LwpDocument
* LwpFootnote::GetEndnoteDivision(LwpDocument
* pPossible
)
305 LwpDocument
* pDivision
= pPossible
;
308 // In case we have multiple endnote divisions, walk backwards until
312 // Do we already have the right division?
313 nDivType
= pDivision
->GetEndnoteType();
314 if (nDivType
== m_nType
)
316 // When we hit the first non-endnote division, stop looking.
318 if (nDivType
== FN_DONTCARE
)
320 pDivision
= pDivision
->GetPreviousDivision();
326 * @descr Get footnote table class name
328 OUString
LwpFootnote::GetTableClass()
330 OUString strClassName
;
331 switch (GetType() & FN_MASK_BASE
)
333 case FN_BASE_FOOTNOTE
:
335 strClassName
= STR_DivisionFootnote
;
338 case FN_BASE_DOCUMENT
:
340 strClassName
= STR_DocumentEndnote
;
343 case FN_BASE_DIVISION
:
345 strClassName
= STR_DivisionEndnote
;
348 case FN_BASE_DIVISIONGROUP
:
350 strClassName
= STR_DivisionGroupEndnote
;
358 * @descr Find footnote tablelayout, copy from lwp source code
360 LwpEnSuperTableLayout
* LwpFootnote::FindFootnoteTableLayout()
362 LwpDocument
* pDivision
= GetFootnoteTableDivision();
366 LwpFoundry
* pFoundry
= pDivision
->GetFoundry();
367 OUString strClassName
= GetTableClass();
368 if(strClassName
.isEmpty() )
371 LwpContent
* pContent
= NULL
;
373 while ((pContent
= pFoundry
->EnumContents(pContent
)) != NULL
)
374 if (pContent
->IsTable() && (strClassName
.equals(pContent
->GetClassName())) &&
375 pContent
->IsActive() && pContent
->GetLayout(NULL
))
378 return (LwpEnSuperTableLayout
*)
379 ((LwpTable
*)pContent
)->GetSuperTableLayout();
386 * @descr Find footnote contents
388 LwpContent
* LwpFootnote::FindFootnoteContent()
390 LwpContent
* pContent
= dynamic_cast<LwpContent
*>(m_Content
.obj());
391 //if the content has layout, the content has footnote contents;
392 //or looking for the celllayout and return the footnote contents.
393 if(pContent
&& pContent
->GetLayout(NULL
))
396 LwpCellLayout
* pCellLayout
= GetCellLayout();
399 pContent
= dynamic_cast<LwpContent
*>(pCellLayout
->GetContent()->obj());
405 LwpFootnoteTable::LwpFootnoteTable(LwpObjectHeader
&objHdr
, LwpSvStream
*pStrm
)
406 : LwpTable(objHdr
, pStrm
)
410 void LwpFootnoteTable::Read()
413 m_pObjStrm
->SkipExtra();
417 * @descr Read footnote number options information
419 void LwpFootnoteNumberOptions::Read(LwpObjectStream
*pObjStrm
)
421 m_nFlag
= pObjStrm
->QuickReaduInt16();
422 m_nStartingNumber
= pObjStrm
->QuickReaduInt16();
423 m_LeadingText
.Read(pObjStrm
);
424 m_TrailingText
.Read(pObjStrm
);
425 pObjStrm
->SkipExtra();
429 * @descr Read footnote separator options information
431 void LwpFootnoteSeparatorOptions::Read(LwpObjectStream
*pObjStrm
)
433 m_nFlag
= pObjStrm
->QuickReaduInt16();
434 m_nLength
= pObjStrm
->QuickReaduInt32();
435 m_nIndent
= pObjStrm
->QuickReaduInt32();
436 m_nAbove
= pObjStrm
->QuickReaduInt32();
437 m_nBelow
= pObjStrm
->QuickReaduInt32();
438 m_BorderStuff
.Read(pObjStrm
);
439 pObjStrm
->SkipExtra();
442 LwpFootnoteOptions::LwpFootnoteOptions(LwpObjectHeader
&objHdr
, LwpSvStream
*pStrm
)
443 : LwpObject(objHdr
, pStrm
)
448 LwpFootnoteOptions::~LwpFootnoteOptions()
454 * @descr Register footnote options object
456 void LwpFootnoteOptions::Read()
458 m_nFlag
= m_pObjStrm
->QuickReaduInt16();
459 m_FootnoteNumbering
.Read(m_pObjStrm
);
460 m_EndnoteDivisionNumbering
.Read(m_pObjStrm
);
461 m_EndnoteDivisionGroupNumbering
.Read(m_pObjStrm
);
462 m_EndnoteDocNumbering
.Read(m_pObjStrm
);
463 m_FootnoteSeparator
.Read(m_pObjStrm
);
464 m_FootnoteContinuedSeparator
.Read(m_pObjStrm
);
465 m_ContinuedOnMessage
.Read(m_pObjStrm
);
466 m_ContinuedFromMessage
.Read(m_pObjStrm
);
467 m_pObjStrm
->SkipExtra();
471 * @descr Register footnote options style
473 void LwpFootnoteOptions::RegisterStyle()
475 RegisterFootnoteStyle();
476 RegisterEndnoteStyle();
480 * @descr Register footnote configuration information
482 void LwpFootnoteOptions::RegisterFootnoteStyle()
484 XFFootnoteConfig
* pFootnoteConfig
= new XFFootnoteConfig();
485 pFootnoteConfig
->SetStartValue(m_FootnoteNumbering
.GetStartingNumber() -1);
486 pFootnoteConfig
->SetNumPrefix(m_FootnoteNumbering
.GetLeadingText());
487 pFootnoteConfig
->SetNumSuffix(m_FootnoteNumbering
.GetTrailingText());
488 if(m_FootnoteNumbering
.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE
)
490 pFootnoteConfig
->SetRestartOnPage();
492 if(GetContinuedFrom())
494 pFootnoteConfig
->SetMessageFrom(GetContinuedFromMessage());
498 pFootnoteConfig
->SetMessageOn(GetContinuedOnMessage());
501 pFootnoteConfig
->SetMasterPage( m_strMasterPage
);
502 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
503 pXFStyleManager
->SetFootnoteConfig(pFootnoteConfig
);
508 * @descr Register endnote configuration information
510 void LwpFootnoteOptions::RegisterEndnoteStyle()
512 XFEndnoteConfig
* pEndnoteConfig
= new XFEndnoteConfig();
513 pEndnoteConfig
->SetStartValue(m_EndnoteDocNumbering
.GetStartingNumber() -1);
514 OUString message
= m_EndnoteDocNumbering
.GetLeadingText();
515 if(message
.isEmpty())
517 message
= "[";//default prefix
519 pEndnoteConfig
->SetNumPrefix(message
);
520 message
= m_EndnoteDocNumbering
.GetTrailingText();
521 if(message
.isEmpty())
523 message
= "]";//default suffix
525 pEndnoteConfig
->SetNumSuffix(message
);
526 if(m_EndnoteDocNumbering
.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE
)
528 pEndnoteConfig
->SetRestartOnPage();
531 pEndnoteConfig
->SetMasterPage( m_strMasterPage
);
533 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
534 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 OUString(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 OUString(STRID_FOOTCONTINUEDFROM
);
563 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */