fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lotuswordpro / source / filter / lwpfootnote.cxx
blob5c64d00ba1a1520845d8c21369090a5e49fca3d4
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 ************************************************************************/
56 /**
57 * @file
58 * footnote
60 /*************************************************************************
61 * Change History
62 Mar 2005 Created
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"
73 #include "lwpdoc.hxx"
74 #include "lwpfnlayout.hxx"
75 #include "lwpglobalmgr.hxx"
77 LwpFribFootnote::LwpFribFootnote(LwpPara* pPara ):LwpFrib(pPara)
81 /**
82 * @descr read footnote frib information
84 void LwpFribFootnote::Read(LwpObjectStream * pObjStrm, sal_uInt16 /*len*/)
86 m_Footnote.ReadIndexed(pObjStrm);
89 /**
90 * @descr Register footnote style by calling LwpFootnote::RegisterStyle()
92 void LwpFribFootnote::RegisterNewStyle()
94 LwpFootnote* pFootnote = GetFootnote();
95 if(pFootnote)
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();
111 if(pFootnote)
113 XFContentContainer* pContent = NULL;
114 if(pFootnote->GetType() == FN_FOOTNOTE)
116 pContent = new XFFootNote();
118 else
120 pContent = new XFEndNote();
122 pFootnote->XFConvert(pContent);
123 if(m_ModFlag)
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);
130 pCont->Add(pSpan);
132 else
134 pCont->Add(pContent);
140 * @descr Get foonote object
142 LwpFootnote* LwpFribFootnote::GetFootnote()
144 return dynamic_cast<LwpFootnote*>(m_Footnote.obj().get());
147 LwpFootnote::LwpFootnote(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
148 : LwpOrderedObject(objHdr, pStrm)
149 , m_nType(0)
150 , m_nRow(0)
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();
181 if(pContent)
183 pContent->SetFoundry(m_pFoundry);
184 pContent->RegisterStyle();
190 * @descr Parse footnote
192 void LwpFootnote::XFConvert(XFContentContainer * pCont)
194 LwpContent* pContent = FindFootnoteContent();
195 if(pContent)
197 pContent->XFConvert(pCont);
202 * @descr Get endnote cell layout which contains current endnote content
204 LwpCellLayout* LwpFootnote::GetCellLayout()
206 LwpEnSuperTableLayout* pEnSuperLayout = FindFootnoteTableLayout();
207 if(pEnSuperLayout)
209 LwpTableLayout* pTableLayout = static_cast<LwpTableLayout*>(pEnSuperLayout->GetMainTableLayout());
210 if(pTableLayout)
212 LwpRowLayout* pRowLayout = pTableLayout->GetRowLayout(m_nRow);
213 if(pRowLayout)
215 return dynamic_cast<LwpCellLayout*>(pRowLayout->GetChildHead().obj().get());
219 return NULL;
223 * @descr Get division which footnote table contains current footnote content, copy from lwp source code
225 LwpDocument* LwpFootnote::GetFootnoteTableDivision()
227 if(!m_pFoundry)
228 return NULL;
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())
239 return NULL;
241 switch (m_nType)
243 case FN_FOOTNOTE:
245 // Footnotes always use the source division
246 return pFootnoteDivision;
248 case FN_DIVISION:
250 // Start with the footnote's division
251 pDivision = pPrev;
252 break;
254 case FN_DIVISION_SEPARATE:
256 // It had better be the next division
257 pDivision = pPrev->GetNextDivision();
258 break;
260 case FN_DIVISIONGROUP:
261 case FN_DIVISIONGROUP_SEPARATE:
263 pDivision = pPrev->GetLastInGroupWithContents();
264 pPrev = pDivision;
265 break;
267 case FN_DOCUMENT:
268 case FN_DOCUMENT_SEPARATE:
270 pDivision = pFootnoteDivision->GetRootDocument();
271 if (pDivision)
272 pDivision = pDivision->GetLastDivisionWithContents();
273 pPrev = pDivision;
274 break;
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
283 else
285 while (pDivision)
287 if (pDivision->GetEndnoteType() == FN_DONTCARE)
288 break;
289 if (m_nType == FN_DIVISIONGROUP)
290 pDivision = pDivision->GetPreviousInGroup();
291 else
292 pDivision = pDivision->GetPreviousDivisionWithContents();
295 if (pDivision)
296 return pDivision;
297 return NULL;
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;
306 sal_uInt16 nDivType;
308 // In case we have multiple endnote divisions, walk backwards until
309 // we find one.
310 while (pDivision)
312 // Do we already have the right division?
313 nDivType = pDivision->GetEndnoteType();
314 if (nDivType == m_nType)
315 return pDivision;
316 // When we hit the first non-endnote division, stop looking.
317 // -- SDC 10/8/96
318 if (nDivType == FN_DONTCARE)
319 break;
320 pDivision = pDivision->GetPreviousDivision();
322 return NULL;
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;
336 break;
338 case FN_BASE_DOCUMENT:
340 strClassName = STR_DocumentEndnote;
341 break;
343 case FN_BASE_DIVISION:
345 strClassName = STR_DivisionEndnote;
346 break;
348 case FN_BASE_DIVISIONGROUP:
350 strClassName = STR_DivisionGroupEndnote;
351 break;
354 return strClassName;
358 * @descr Find footnote tablelayout, copy from lwp source code
360 LwpEnSuperTableLayout* LwpFootnote::FindFootnoteTableLayout()
362 LwpDocument* pDivision = GetFootnoteTableDivision();
363 if(!pDivision)
364 return NULL;
366 LwpFoundry* pFoundry = pDivision->GetFoundry();
367 OUString strClassName = GetTableClass();
368 if(strClassName.isEmpty() )
369 return NULL;
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))
377 // Found it!
378 return static_cast<LwpEnSuperTableLayout *>(
379 static_cast<LwpTable*>(pContent)->GetSuperTableLayout());
382 return NULL;
386 * @descr Find footnote contents
388 LwpContent* LwpFootnote::FindFootnoteContent()
390 LwpContent* pContent = dynamic_cast<LwpContent*>(m_Content.obj().get());
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))
394 return pContent;
396 LwpCellLayout* pCellLayout = GetCellLayout();
397 if(pCellLayout)
399 pContent = dynamic_cast<LwpContent*>(pCellLayout->GetContent().obj().get());
402 return pContent;
405 LwpFootnoteTable::LwpFootnoteTable(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
406 : LwpTable(objHdr, pStrm)
410 void LwpFootnoteTable::Read()
412 LwpTable::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)
444 , m_nFlag(0)
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());
496 if(GetContinuedOn())
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: */