build fix
[LibreOffice.git] / lotuswordpro / source / filter / lwpfootnote.cxx
blobb8ac3fd027f520e987c799c894648b41572c3e3d
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,
29 * MA 02111-1307 USA
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 ************************************************************************/
57 #include "lwpfootnote.hxx"
58 #include "lwpstory.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"
66 #include "lwpdoc.hxx"
67 #include "lwpfnlayout.hxx"
68 #include "lwpglobalmgr.hxx"
70 LwpFribFootnote::LwpFribFootnote(LwpPara* pPara ):LwpFrib(pPara)
74 /**
75 * @descr read footnote frib information
77 void LwpFribFootnote::Read(LwpObjectStream * pObjStrm, sal_uInt16 /*len*/)
79 m_Footnote.ReadIndexed(pObjStrm);
82 /**
83 * @descr Register footnote style by calling LwpFootnote::RegisterStyle()
85 void LwpFribFootnote::RegisterNewStyle()
87 LwpFootnote* pFootnote = GetFootnote();
88 if(pFootnote)
90 //register footnote number font style
91 LwpFrib::RegisterStyle(m_pPara->GetFoundry());
92 //register footnote content style
93 pFootnote->SetFoundry(m_pPara->GetFoundry());
94 pFootnote->RegisterStyle();
98 /**
99 * @descr Parse footnote by calling LwpFootnote::XFConvert()
101 void LwpFribFootnote::XFConvert(XFContentContainer* pCont)
103 LwpFootnote* pFootnote = GetFootnote();
104 if(pFootnote)
106 XFContentContainer* pContent = nullptr;
107 if(pFootnote->GetType() == FN_FOOTNOTE)
109 pContent = new XFFootNote();
111 else
113 pContent = new XFEndNote();
115 pFootnote->XFConvert(pContent);
116 if(m_ModFlag)
118 //set footnote number font style
119 XFTextSpan *pSpan = new XFTextSpan();
120 pSpan->SetStyleName(GetStyleName());
121 //add the xffootnote into the content container
122 pSpan->Add(pContent);
123 pCont->Add(pSpan);
125 else
127 pCont->Add(pContent);
133 * @descr Get foonote object
135 LwpFootnote* LwpFribFootnote::GetFootnote()
137 return dynamic_cast<LwpFootnote*>(m_Footnote.obj().get());
140 LwpFootnote::LwpFootnote(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
141 : LwpOrderedObject(objHdr, pStrm)
142 , m_nType(0)
143 , m_nRow(0)
147 LwpFootnote::~LwpFootnote()
153 * @descr Read foonote object
155 void LwpFootnote::Read()
157 LwpOrderedObject::Read();
158 m_nType = m_pObjStrm->QuickReaduInt16();
159 m_nRow = m_pObjStrm->QuickReaduInt16();
160 m_Content.ReadIndexed(m_pObjStrm.get());
161 m_pObjStrm->SkipExtra();
165 * @descr Register footnote style
167 void LwpFootnote::RegisterStyle()
169 //Only register footnote contents style,
170 //Endnote contents style registers in LwpEnSuperTableLayout::RegisterStyle
171 if(m_nType == FN_FOOTNOTE)
173 LwpContent* pContent = FindFootnoteContent();
174 if(pContent)
176 pContent->SetFoundry(m_pFoundry);
177 pContent->DoRegisterStyle();
183 * @descr Parse footnote
185 void LwpFootnote::XFConvert(XFContentContainer * pCont)
187 LwpContent* pContent = FindFootnoteContent();
188 if(pContent)
190 pContent->DoXFConvert(pCont);
195 * @descr Get endnote cell layout which contains current endnote content
197 LwpCellLayout* LwpFootnote::GetCellLayout()
199 LwpEnSuperTableLayout* pEnSuperLayout = FindFootnoteTableLayout();
200 if(pEnSuperLayout)
202 LwpTableLayout* pTableLayout = dynamic_cast<LwpTableLayout*>(pEnSuperLayout->GetMainTableLayout());
203 if(pTableLayout)
205 LwpRowLayout* pRowLayout = pTableLayout->GetRowLayout(m_nRow);
206 if(pRowLayout)
208 return dynamic_cast<LwpCellLayout*>(pRowLayout->GetChildHead().obj().get());
212 return nullptr;
216 * @descr Get division which footnote table contains current footnote content, copy from lwp source code
218 LwpDocument* LwpFootnote::GetFootnoteTableDivision()
220 if(!m_pFoundry)
221 return nullptr;
223 LwpDocument* pPrev =nullptr;
224 LwpDocument* pDivision = nullptr;
225 LwpDocument* pFootnoteDivision =nullptr;
227 // Make sure the footnote does belong to some division
228 // The division might not have a DivisionInfo if it's being Destruct()ed
229 pPrev = m_pFoundry->GetDocument();
230 pFootnoteDivision = pPrev;
231 if (!pPrev || pPrev->GetDivInfoID().IsNull())
232 return nullptr;
234 switch (m_nType)
236 case FN_FOOTNOTE:
238 // Footnotes always use the source division
239 return pFootnoteDivision;
241 case FN_DIVISION:
243 // Start with the footnote's division
244 pDivision = pPrev;
245 break;
247 case FN_DIVISION_SEPARATE:
249 // It had better be the next division
250 pDivision = pPrev->GetNextDivision();
251 break;
253 case FN_DIVISIONGROUP:
254 case FN_DIVISIONGROUP_SEPARATE:
256 pDivision = pPrev->GetLastInGroupWithContents();
257 break;
259 case FN_DOCUMENT:
260 case FN_DOCUMENT_SEPARATE:
262 pDivision = pFootnoteDivision->GetRootDocument();
263 if (pDivision)
264 pDivision = pDivision->GetLastDivisionWithContents();
265 break;
270 // Make sure we're using the proper endnote division, if it's separate
271 if (m_nType & FN_MASK_SEPARATE)
272 pDivision = GetEndnoteDivision(pDivision);
273 // Don't use a division that's specifically for endnotes
274 else
276 while (pDivision)
278 if (pDivision->GetEndnoteType() == FN_DONTCARE)
279 break;
280 if (m_nType == FN_DIVISIONGROUP)
281 pDivision = pDivision->GetPreviousInGroup();
282 else
283 pDivision = pDivision->GetPreviousDivisionWithContents();
286 if (pDivision)
287 return pDivision;
288 return nullptr;
292 * @descr Get division which endnote table contains current endnote content, copy from lwp source code
294 LwpDocument* LwpFootnote::GetEndnoteDivision(LwpDocument* pPossible)
296 LwpDocument* pDivision = pPossible;
297 sal_uInt16 nDivType;
299 // In case we have multiple endnote divisions, walk backwards until
300 // we find one.
301 while (pDivision)
303 // Do we already have the right division?
304 nDivType = pDivision->GetEndnoteType();
305 if (nDivType == m_nType)
306 return pDivision;
307 // When we hit the first non-endnote division, stop looking.
308 // -- SDC 10/8/96
309 if (nDivType == FN_DONTCARE)
310 break;
311 pDivision = pDivision->GetPreviousDivision();
313 return nullptr;
317 * @descr Get footnote table class name
319 OUString LwpFootnote::GetTableClass()
321 OUString strClassName;
322 switch (GetType() & FN_MASK_BASE)
324 case FN_BASE_FOOTNOTE:
326 strClassName = STR_DivisionFootnote;
327 break;
329 case FN_BASE_DOCUMENT:
331 strClassName = STR_DocumentEndnote;
332 break;
334 case FN_BASE_DIVISION:
336 strClassName = STR_DivisionEndnote;
337 break;
339 case FN_BASE_DIVISIONGROUP:
341 strClassName = STR_DivisionGroupEndnote;
342 break;
345 return strClassName;
349 * @descr Find footnote tablelayout, copy from lwp source code
351 LwpEnSuperTableLayout* LwpFootnote::FindFootnoteTableLayout()
353 LwpDocument* pDivision = GetFootnoteTableDivision();
354 if(!pDivision)
355 return nullptr;
357 LwpFoundry* pFoundry = pDivision->GetFoundry();
358 OUString strClassName = GetTableClass();
359 if(strClassName.isEmpty() )
360 return nullptr;
362 LwpContent* pContent = nullptr;
364 while ((pContent = pFoundry->EnumContents(pContent)) != nullptr)
365 if (pContent->IsTable() && (strClassName.equals(pContent->GetClassName())) &&
366 pContent->IsActive() && pContent->GetLayout(nullptr).is())
368 // Found it!
369 return static_cast<LwpEnSuperTableLayout *>(
370 static_cast<LwpTable*>(pContent)->GetSuperTableLayout());
373 return nullptr;
377 * @descr Find footnote contents
379 LwpContent* LwpFootnote::FindFootnoteContent()
381 LwpContent* pContent = dynamic_cast<LwpContent*>(m_Content.obj().get());
382 //if the content has layout, the content has footnote contents;
383 //or looking for the celllayout and return the footnote contents.
384 if (pContent && pContent->GetLayout(nullptr).is())
385 return pContent;
387 LwpCellLayout* pCellLayout = GetCellLayout();
388 if(pCellLayout)
390 pContent = dynamic_cast<LwpContent*>(pCellLayout->GetContent().obj().get());
393 return pContent;
396 LwpFootnoteTable::LwpFootnoteTable(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
397 : LwpTable(objHdr, pStrm)
401 void LwpFootnoteTable::Read()
403 LwpTable::Read();
404 m_pObjStrm->SkipExtra();
408 * @descr Read footnote number options information
410 void LwpFootnoteNumberOptions::Read(LwpObjectStream *pObjStrm)
412 m_nFlag = pObjStrm->QuickReaduInt16();
413 m_nStartingNumber = pObjStrm->QuickReaduInt16();
414 m_LeadingText.Read(pObjStrm);
415 m_TrailingText.Read(pObjStrm);
416 pObjStrm->SkipExtra();
420 * @descr Read footnote separator options information
422 void LwpFootnoteSeparatorOptions::Read(LwpObjectStream *pObjStrm)
424 m_nFlag = pObjStrm->QuickReaduInt16();
425 m_nLength = pObjStrm->QuickReaduInt32();
426 m_nIndent = pObjStrm->QuickReaduInt32();
427 m_nAbove = pObjStrm->QuickReaduInt32();
428 m_nBelow = pObjStrm->QuickReaduInt32();
429 m_BorderStuff.Read(pObjStrm);
430 pObjStrm->SkipExtra();
433 LwpFootnoteOptions::LwpFootnoteOptions(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
434 : LwpObject(objHdr, pStrm)
435 , m_nFlag(0)
439 LwpFootnoteOptions::~LwpFootnoteOptions()
445 * @descr Register footnote options object
447 void LwpFootnoteOptions::Read()
449 m_nFlag = m_pObjStrm->QuickReaduInt16();
450 m_FootnoteNumbering.Read(m_pObjStrm.get());
451 m_EndnoteDivisionNumbering.Read(m_pObjStrm.get());
452 m_EndnoteDivisionGroupNumbering.Read(m_pObjStrm.get());
453 m_EndnoteDocNumbering.Read(m_pObjStrm.get());
454 m_FootnoteSeparator.Read(m_pObjStrm.get());
455 m_FootnoteContinuedSeparator.Read(m_pObjStrm.get());
456 m_ContinuedOnMessage.Read(m_pObjStrm.get());
457 m_ContinuedFromMessage.Read(m_pObjStrm.get());
458 m_pObjStrm->SkipExtra();
462 * @descr Register footnote options style
464 void LwpFootnoteOptions::RegisterStyle()
466 RegisterFootnoteStyle();
467 RegisterEndnoteStyle();
471 * @descr Register footnote configuration information
473 void LwpFootnoteOptions::RegisterFootnoteStyle()
475 XFFootnoteConfig* pFootnoteConfig = new XFFootnoteConfig();
476 pFootnoteConfig->SetStartValue(m_FootnoteNumbering.GetStartingNumber() -1);
477 pFootnoteConfig->SetNumPrefix(m_FootnoteNumbering.GetLeadingText());
478 pFootnoteConfig->SetNumSuffix(m_FootnoteNumbering.GetTrailingText());
479 if(m_FootnoteNumbering.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE)
481 pFootnoteConfig->SetRestartOnPage();
483 if(GetContinuedFrom())
485 pFootnoteConfig->SetMessageFrom(GetContinuedFromMessage());
487 if(GetContinuedOn())
489 pFootnoteConfig->SetMessageOn(GetContinuedOnMessage());
492 pFootnoteConfig->SetMasterPage( m_strMasterPage);
493 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
494 pXFStyleManager->SetFootnoteConfig(pFootnoteConfig);
499 * @descr Register endnote configuration information
501 void LwpFootnoteOptions::RegisterEndnoteStyle()
503 XFEndnoteConfig* pEndnoteConfig = new XFEndnoteConfig();
504 pEndnoteConfig->SetStartValue(m_EndnoteDocNumbering.GetStartingNumber() -1);
505 OUString message = m_EndnoteDocNumbering.GetLeadingText();
506 if(message.isEmpty())
508 message = "[";//default prefix
510 pEndnoteConfig->SetNumPrefix(message);
511 message = m_EndnoteDocNumbering.GetTrailingText();
512 if(message.isEmpty())
514 message = "]";//default suffix
516 pEndnoteConfig->SetNumSuffix(message);
517 if(m_EndnoteDocNumbering.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE)
519 pEndnoteConfig->SetRestartOnPage();
522 pEndnoteConfig->SetMasterPage( m_strMasterPage);
524 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
525 pXFStyleManager->SetEndnoteConfig(pEndnoteConfig);
529 * @descr Get continue on message
531 OUString LwpFootnoteOptions::GetContinuedOnMessage()
533 if(m_ContinuedOnMessage.HasValue())
535 return m_ContinuedOnMessage.str();
537 // else reture defauls message
538 return OUString(STRID_FOOTCONTINUEDON);
542 * @descr Get continue from message
544 OUString LwpFootnoteOptions::GetContinuedFromMessage()
546 if(m_ContinuedFromMessage.HasValue())
548 return m_ContinuedFromMessage.str();
550 // else reture defauls message
551 return OUString(STRID_FOOTCONTINUEDFROM);
554 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */