Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
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
16 : *
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.
20 : *
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.
25 : *
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
30 : *
31 : *
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.
38 : *
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.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : /**
57 : * @file
58 : * footnote
59 : */
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"
76 :
77 1 : LwpFribFootnote::LwpFribFootnote(LwpPara* pPara ):LwpFrib(pPara)
78 : {
79 1 : }
80 :
81 : /**
82 : * @descr read footnote frib information
83 : */
84 1 : void LwpFribFootnote::Read(LwpObjectStream * pObjStrm, sal_uInt16 /*len*/)
85 : {
86 1 : m_Footnote.ReadIndexed(pObjStrm);
87 1 : }
88 :
89 : /**
90 : * @descr Register footnote style by calling LwpFootnote::RegisterStyle()
91 : */
92 1 : void LwpFribFootnote::RegisterNewStyle()
93 : {
94 1 : LwpFootnote* pFootnote = GetFootnote();
95 1 : if(pFootnote)
96 : {
97 : //register footnote number font style
98 1 : LwpFrib::RegisterStyle(m_pPara->GetFoundry());
99 : //register footnote content style
100 1 : pFootnote->SetFoundry(m_pPara->GetFoundry());
101 1 : pFootnote->RegisterStyle();
102 : }
103 1 : }
104 :
105 : /**
106 : * @descr Parse footnote by calling LwpFootnote::XFConvert()
107 : */
108 1 : void LwpFribFootnote::XFConvert(XFContentContainer* pCont)
109 : {
110 1 : LwpFootnote* pFootnote = GetFootnote();
111 1 : if(pFootnote)
112 : {
113 1 : XFContentContainer* pContent = NULL;
114 1 : if(pFootnote->GetType() == FN_FOOTNOTE)
115 : {
116 1 : pContent = new XFFootNote();
117 : }
118 : else
119 : {
120 0 : pContent = new XFEndNote();
121 : }
122 1 : pFootnote->XFConvert(pContent);
123 1 : if(m_ModFlag)
124 : {
125 : //set footnote number font style
126 1 : XFTextSpan *pSpan = new XFTextSpan();
127 1 : pSpan->SetStyleName(GetStyleName());
128 : //add the xffootnote into the content container
129 1 : pSpan->Add(pContent);
130 1 : pCont->Add(pSpan);
131 : }
132 : else
133 : {
134 0 : pCont->Add(pContent);
135 : }
136 : }
137 1 : }
138 :
139 : /**
140 : * @descr Get foonote object
141 : */
142 2 : LwpFootnote* LwpFribFootnote::GetFootnote()
143 : {
144 2 : return dynamic_cast<LwpFootnote*>(m_Footnote.obj().get());
145 : }
146 :
147 1 : LwpFootnote::LwpFootnote(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
148 : : LwpOrderedObject(objHdr, pStrm)
149 : , m_nType(0)
150 1 : , m_nRow(0)
151 : {
152 1 : }
153 :
154 2 : LwpFootnote::~LwpFootnote()
155 : {
156 :
157 2 : }
158 :
159 : /**
160 : * @descr Read foonote object
161 : */
162 1 : void LwpFootnote::Read()
163 : {
164 1 : LwpOrderedObject::Read();
165 1 : m_nType = m_pObjStrm->QuickReaduInt16();
166 1 : m_nRow = m_pObjStrm->QuickReaduInt16();
167 1 : m_Content.ReadIndexed(m_pObjStrm);
168 1 : m_pObjStrm->SkipExtra();
169 1 : }
170 :
171 : /**
172 : * @descr Register footnote style
173 : */
174 1 : void LwpFootnote::RegisterStyle()
175 : {
176 : //Only register footnote contents style,
177 : //Endnote contents style registers in LwpEnSuperTableLayout::RegisterStyle
178 1 : if(m_nType == FN_FOOTNOTE)
179 : {
180 1 : LwpContent* pContent = FindFootnoteContent();
181 1 : if(pContent)
182 : {
183 1 : pContent->SetFoundry(m_pFoundry);
184 1 : pContent->RegisterStyle();
185 : }
186 : }
187 1 : }
188 :
189 : /**
190 : * @descr Parse footnote
191 : */
192 1 : void LwpFootnote::XFConvert(XFContentContainer * pCont)
193 : {
194 1 : LwpContent* pContent = FindFootnoteContent();
195 1 : if(pContent)
196 : {
197 1 : pContent->XFConvert(pCont);
198 : }
199 1 : }
200 :
201 : /**
202 : * @descr Get endnote cell layout which contains current endnote content
203 : */
204 0 : LwpCellLayout* LwpFootnote::GetCellLayout()
205 : {
206 0 : LwpEnSuperTableLayout* pEnSuperLayout = FindFootnoteTableLayout();
207 0 : if(pEnSuperLayout)
208 : {
209 0 : LwpTableLayout* pTableLayout = static_cast<LwpTableLayout*>(pEnSuperLayout->GetMainTableLayout());
210 0 : if(pTableLayout)
211 : {
212 0 : LwpRowLayout* pRowLayout = pTableLayout->GetRowLayout(m_nRow);
213 0 : if(pRowLayout)
214 : {
215 0 : return dynamic_cast<LwpCellLayout*>(pRowLayout->GetChildHead().obj().get());
216 : }
217 : }
218 : }
219 0 : return NULL;
220 : }
221 :
222 : /**
223 : * @descr Get division which footnote table contains current footnote content, copy from lwp source code
224 : */
225 0 : LwpDocument* LwpFootnote::GetFootnoteTableDivision()
226 : {
227 0 : if(!m_pFoundry)
228 0 : return NULL;
229 :
230 0 : LwpDocument* pPrev =NULL;
231 0 : LwpDocument* pDivision = NULL;
232 0 : LwpDocument* pFootnoteDivision =NULL;
233 :
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 0 : pPrev = m_pFoundry->GetDocument();
237 0 : pFootnoteDivision = pPrev;
238 0 : if (!pPrev || pPrev->GetDivInfoID().IsNull())
239 0 : return NULL;
240 :
241 0 : switch (m_nType)
242 : {
243 : case FN_FOOTNOTE:
244 : {
245 : // Footnotes always use the source division
246 0 : return pFootnoteDivision;
247 : }
248 : case FN_DIVISION:
249 : {
250 : // Start with the footnote's division
251 0 : pDivision = pPrev;
252 0 : break;
253 : }
254 : case FN_DIVISION_SEPARATE:
255 : {
256 : // It had better be the next division
257 0 : pDivision = pPrev->GetNextDivision();
258 0 : break;
259 : }
260 : case FN_DIVISIONGROUP:
261 : case FN_DIVISIONGROUP_SEPARATE:
262 : {
263 0 : pDivision = pPrev->GetLastInGroupWithContents();
264 0 : pPrev = pDivision;
265 0 : break;
266 : }
267 : case FN_DOCUMENT:
268 : case FN_DOCUMENT_SEPARATE:
269 : {
270 0 : pDivision = pFootnoteDivision->GetRootDocument();
271 0 : if (pDivision)
272 0 : pDivision = pDivision->GetLastDivisionWithContents();
273 0 : pPrev = pDivision;
274 0 : break;
275 : }
276 :
277 : }
278 :
279 : // Make sure we're using the proper endnote division, if it's separate
280 0 : if (m_nType & FN_MASK_SEPARATE)
281 0 : pDivision = GetEndnoteDivision(pDivision);
282 : // Don't use a division that's specifically for endnotes
283 : else
284 : {
285 0 : while (pDivision)
286 : {
287 0 : if (pDivision->GetEndnoteType() == FN_DONTCARE)
288 0 : break;
289 0 : if (m_nType == FN_DIVISIONGROUP)
290 0 : pDivision = pDivision->GetPreviousInGroup();
291 : else
292 0 : pDivision = pDivision->GetPreviousDivisionWithContents();
293 : }
294 : }
295 0 : if (pDivision)
296 0 : return pDivision;
297 0 : return NULL;
298 : }
299 :
300 : /**
301 : * @descr Get division which endnote table contains current endnote content, copy from lwp source code
302 : */
303 0 : LwpDocument* LwpFootnote::GetEndnoteDivision(LwpDocument* pPossible)
304 : {
305 0 : LwpDocument* pDivision = pPossible;
306 : sal_uInt16 nDivType;
307 :
308 : // In case we have multiple endnote divisions, walk backwards until
309 : // we find one.
310 0 : while (pDivision)
311 : {
312 : // Do we already have the right division?
313 0 : nDivType = pDivision->GetEndnoteType();
314 0 : if (nDivType == m_nType)
315 0 : return pDivision;
316 : // When we hit the first non-endnote division, stop looking.
317 : // -- SDC 10/8/96
318 0 : if (nDivType == FN_DONTCARE)
319 0 : break;
320 0 : pDivision = pDivision->GetPreviousDivision();
321 : }
322 0 : return NULL;
323 : }
324 :
325 : /**
326 : * @descr Get footnote table class name
327 : */
328 0 : OUString LwpFootnote::GetTableClass()
329 : {
330 0 : OUString strClassName;
331 0 : switch (GetType() & FN_MASK_BASE)
332 : {
333 : case FN_BASE_FOOTNOTE:
334 : {
335 0 : strClassName = STR_DivisionFootnote;
336 0 : break;
337 : }
338 : case FN_BASE_DOCUMENT:
339 : {
340 0 : strClassName = STR_DocumentEndnote;
341 0 : break;
342 : }
343 : case FN_BASE_DIVISION:
344 : {
345 0 : strClassName = STR_DivisionEndnote;
346 0 : break;
347 : }
348 : case FN_BASE_DIVISIONGROUP:
349 : {
350 0 : strClassName = STR_DivisionGroupEndnote;
351 0 : break;
352 : }
353 : }
354 0 : return strClassName;
355 : }
356 :
357 : /**
358 : * @descr Find footnote tablelayout, copy from lwp source code
359 : */
360 0 : LwpEnSuperTableLayout* LwpFootnote::FindFootnoteTableLayout()
361 : {
362 0 : LwpDocument* pDivision = GetFootnoteTableDivision();
363 0 : if(!pDivision)
364 0 : return NULL;
365 :
366 0 : LwpFoundry* pFoundry = pDivision->GetFoundry();
367 0 : OUString strClassName = GetTableClass();
368 0 : if(strClassName.isEmpty() )
369 0 : return NULL;
370 :
371 0 : LwpContent* pContent = NULL;
372 :
373 0 : while ((pContent = pFoundry->EnumContents(pContent)) != NULL)
374 0 : if (pContent->IsTable() && (strClassName.equals(pContent->GetClassName())) &&
375 0 : pContent->IsActive() && pContent->GetLayout(NULL))
376 : {
377 : // Found it!
378 : return static_cast<LwpEnSuperTableLayout *>(
379 0 : static_cast<LwpTable*>(pContent)->GetSuperTableLayout());
380 : }
381 :
382 0 : return NULL;
383 : }
384 :
385 : /**
386 : * @descr Find footnote contents
387 : */
388 2 : LwpContent* LwpFootnote::FindFootnoteContent()
389 : {
390 2 : 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 2 : if(pContent && pContent->GetLayout(NULL))
394 2 : return pContent;
395 :
396 0 : LwpCellLayout* pCellLayout = GetCellLayout();
397 0 : if(pCellLayout)
398 : {
399 0 : pContent = dynamic_cast<LwpContent*>(pCellLayout->GetContent().obj().get());
400 : }
401 :
402 0 : return pContent;
403 : }
404 :
405 1 : LwpFootnoteTable::LwpFootnoteTable(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
406 1 : : LwpTable(objHdr, pStrm)
407 : {
408 1 : }
409 :
410 1 : void LwpFootnoteTable::Read()
411 : {
412 1 : LwpTable::Read();
413 1 : m_pObjStrm->SkipExtra();
414 1 : }
415 :
416 : /**
417 : * @descr Read footnote number options information
418 : */
419 16 : void LwpFootnoteNumberOptions::Read(LwpObjectStream *pObjStrm)
420 : {
421 16 : m_nFlag = pObjStrm->QuickReaduInt16();
422 16 : m_nStartingNumber = pObjStrm->QuickReaduInt16();
423 16 : m_LeadingText.Read(pObjStrm);
424 16 : m_TrailingText.Read(pObjStrm);
425 16 : pObjStrm->SkipExtra();
426 16 : }
427 :
428 : /**
429 : * @descr Read footnote separator options information
430 : */
431 8 : void LwpFootnoteSeparatorOptions::Read(LwpObjectStream *pObjStrm)
432 : {
433 8 : m_nFlag = pObjStrm->QuickReaduInt16();
434 8 : m_nLength = pObjStrm->QuickReaduInt32();
435 8 : m_nIndent = pObjStrm->QuickReaduInt32();
436 8 : m_nAbove = pObjStrm->QuickReaduInt32();
437 8 : m_nBelow = pObjStrm->QuickReaduInt32();
438 8 : m_BorderStuff.Read(pObjStrm);
439 8 : pObjStrm->SkipExtra();
440 8 : }
441 :
442 4 : LwpFootnoteOptions::LwpFootnoteOptions(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
443 : : LwpObject(objHdr, pStrm)
444 4 : , m_nFlag(0)
445 : {
446 4 : }
447 :
448 8 : LwpFootnoteOptions::~LwpFootnoteOptions()
449 : {
450 :
451 8 : }
452 :
453 : /**
454 : * @descr Register footnote options object
455 : */
456 4 : void LwpFootnoteOptions::Read()
457 : {
458 4 : m_nFlag = m_pObjStrm->QuickReaduInt16();
459 4 : m_FootnoteNumbering.Read(m_pObjStrm);
460 4 : m_EndnoteDivisionNumbering.Read(m_pObjStrm);
461 4 : m_EndnoteDivisionGroupNumbering.Read(m_pObjStrm);
462 4 : m_EndnoteDocNumbering.Read(m_pObjStrm);
463 4 : m_FootnoteSeparator.Read(m_pObjStrm);
464 4 : m_FootnoteContinuedSeparator.Read(m_pObjStrm);
465 4 : m_ContinuedOnMessage.Read(m_pObjStrm);
466 4 : m_ContinuedFromMessage.Read(m_pObjStrm);
467 4 : m_pObjStrm->SkipExtra();
468 4 : }
469 :
470 : /**
471 : * @descr Register footnote options style
472 : */
473 4 : void LwpFootnoteOptions::RegisterStyle()
474 : {
475 4 : RegisterFootnoteStyle();
476 4 : RegisterEndnoteStyle();
477 4 : }
478 :
479 : /**
480 : * @descr Register footnote configuration information
481 : */
482 4 : void LwpFootnoteOptions::RegisterFootnoteStyle()
483 : {
484 4 : XFFootnoteConfig* pFootnoteConfig = new XFFootnoteConfig();
485 4 : pFootnoteConfig->SetStartValue(m_FootnoteNumbering.GetStartingNumber() -1);
486 4 : pFootnoteConfig->SetNumPrefix(m_FootnoteNumbering.GetLeadingText());
487 4 : pFootnoteConfig->SetNumSuffix(m_FootnoteNumbering.GetTrailingText());
488 4 : if(m_FootnoteNumbering.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE)
489 : {
490 0 : pFootnoteConfig->SetRestartOnPage();
491 : }
492 4 : if(GetContinuedFrom())
493 : {
494 0 : pFootnoteConfig->SetMessageFrom(GetContinuedFromMessage());
495 : }
496 4 : if(GetContinuedOn())
497 : {
498 0 : pFootnoteConfig->SetMessageOn(GetContinuedOnMessage());
499 : }
500 :
501 4 : pFootnoteConfig->SetMasterPage( m_strMasterPage);
502 4 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
503 4 : pXFStyleManager->SetFootnoteConfig(pFootnoteConfig);
504 :
505 4 : }
506 :
507 : /**
508 : * @descr Register endnote configuration information
509 : */
510 4 : void LwpFootnoteOptions::RegisterEndnoteStyle()
511 : {
512 4 : XFEndnoteConfig* pEndnoteConfig = new XFEndnoteConfig();
513 4 : pEndnoteConfig->SetStartValue(m_EndnoteDocNumbering.GetStartingNumber() -1);
514 4 : OUString message = m_EndnoteDocNumbering.GetLeadingText();
515 4 : if(message.isEmpty())
516 : {
517 4 : message = "[";//default prefix
518 : }
519 4 : pEndnoteConfig->SetNumPrefix(message);
520 4 : message = m_EndnoteDocNumbering.GetTrailingText();
521 4 : if(message.isEmpty())
522 : {
523 4 : message = "]";//default suffix
524 : }
525 4 : pEndnoteConfig->SetNumSuffix(message);
526 4 : if(m_EndnoteDocNumbering.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE)
527 : {
528 0 : pEndnoteConfig->SetRestartOnPage();
529 : }
530 :
531 4 : pEndnoteConfig->SetMasterPage( m_strMasterPage);
532 :
533 4 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
534 4 : pXFStyleManager->SetEndnoteConfig(pEndnoteConfig);
535 4 : }
536 :
537 : /**
538 : * @descr Get continue on message
539 : */
540 0 : OUString LwpFootnoteOptions::GetContinuedOnMessage()
541 : {
542 0 : if(m_ContinuedOnMessage.HasValue())
543 : {
544 0 : return m_ContinuedOnMessage.str();
545 : }
546 : // else reture defauls message
547 0 : return OUString(STRID_FOOTCONTINUEDON);
548 : }
549 :
550 : /**
551 : * @descr Get continue from message
552 : */
553 0 : OUString LwpFootnoteOptions::GetContinuedFromMessage()
554 : {
555 0 : if(m_ContinuedFromMessage.HasValue())
556 : {
557 0 : return m_ContinuedFromMessage.str();
558 : }
559 : // else reture defauls message
560 0 : return OUString(STRID_FOOTCONTINUEDFROM);
561 : }
562 :
563 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|