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());
145 : }
146 :
147 :
148 1 : LwpFootnote::LwpFootnote(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
149 1 : : LwpOrderedObject(objHdr, pStrm)
150 : {
151 1 : }
152 :
153 2 : LwpFootnote::~LwpFootnote()
154 : {
155 :
156 2 : }
157 :
158 : /**
159 : * @descr Read foonote object
160 : */
161 1 : void LwpFootnote::Read()
162 : {
163 1 : LwpOrderedObject::Read();
164 1 : m_nType = m_pObjStrm->QuickReaduInt16();
165 1 : m_nRow = m_pObjStrm->QuickReaduInt16();
166 1 : m_Content.ReadIndexed(m_pObjStrm);
167 1 : m_pObjStrm->SkipExtra();
168 1 : }
169 :
170 : /**
171 : * @descr Register footnote style
172 : */
173 1 : void LwpFootnote::RegisterStyle()
174 : {
175 : //Only register footnote contents style,
176 : //Endnote contents style registers in LwpEnSuperTableLayout::RegisterStyle
177 1 : if(m_nType == FN_FOOTNOTE)
178 : {
179 1 : LwpContent* pContent = FindFootnoteContent();
180 1 : if(pContent)
181 : {
182 1 : pContent->SetFoundry(m_pFoundry);
183 1 : pContent->RegisterStyle();
184 : }
185 : }
186 1 : }
187 :
188 : /**
189 : * @descr Parse footnote
190 : */
191 1 : void LwpFootnote::XFConvert(XFContentContainer * pCont)
192 : {
193 1 : LwpContent* pContent = FindFootnoteContent();
194 1 : if(pContent)
195 : {
196 1 : pContent->XFConvert(pCont);
197 : }
198 1 : }
199 :
200 : /**
201 : * @descr Get endnote cell layout which contains current endnote content
202 : */
203 0 : LwpCellLayout* LwpFootnote::GetCellLayout()
204 : {
205 0 : LwpEnSuperTableLayout* pEnSuperLayout = FindFootnoteTableLayout();
206 0 : if(pEnSuperLayout)
207 : {
208 0 : LwpTableLayout* pTableLayout = static_cast<LwpTableLayout*>(pEnSuperLayout->GetMainTableLayout());
209 0 : if(pTableLayout)
210 : {
211 0 : LwpRowLayout* pRowLayout = pTableLayout->GetRowLayout(m_nRow);
212 0 : if(pRowLayout)
213 : {
214 0 : return dynamic_cast<LwpCellLayout*>(pRowLayout->GetChildHead()->obj());
215 : }
216 : }
217 : }
218 0 : return NULL;
219 : }
220 :
221 : /**
222 : * @descr Get division which footnote table contains current footnote content, copy from lwp source code
223 : */
224 0 : LwpDocument* LwpFootnote::GetFootnoteTableDivision()
225 : {
226 0 : if(!m_pFoundry)
227 0 : return NULL;
228 :
229 0 : LwpDocument* pPrev =NULL;
230 0 : LwpDocument* pDivision = NULL;
231 0 : LwpDocument* pFootnoteDivision =NULL;
232 :
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 0 : pPrev = m_pFoundry->GetDocument();
236 0 : pFootnoteDivision = pPrev;
237 0 : if (!pPrev || pPrev->GetDivInfoID()->IsNull())
238 0 : return NULL;
239 :
240 0 : switch (m_nType)
241 : {
242 : case FN_FOOTNOTE:
243 : {
244 : // Footnotes always use the source division
245 0 : return pFootnoteDivision;
246 : }
247 : case FN_DIVISION:
248 : {
249 : // Start with the footnote's division
250 0 : pDivision = pPrev;
251 0 : break;
252 : }
253 : case FN_DIVISION_SEPARATE:
254 : {
255 : // It had better be the next division
256 0 : pDivision = pPrev->GetNextDivision();
257 0 : break;
258 : }
259 : case FN_DIVISIONGROUP:
260 : case FN_DIVISIONGROUP_SEPARATE:
261 : {
262 0 : pDivision = pPrev->GetLastInGroupWithContents();
263 0 : pPrev = pDivision;
264 0 : break;
265 : }
266 : case FN_DOCUMENT:
267 : case FN_DOCUMENT_SEPARATE:
268 : {
269 0 : pDivision = pFootnoteDivision->GetRootDocument();
270 0 : if (pDivision)
271 0 : pDivision = pDivision->GetLastDivisionWithContents();
272 0 : pPrev = pDivision;
273 0 : break;
274 : }
275 :
276 : }
277 :
278 : // Make sure we're using the proper endnote division, if it's separate
279 0 : if (m_nType & FN_MASK_SEPARATE)
280 0 : pDivision = GetEndnoteDivision(pDivision);
281 : // Don't use a division that's specifically for endnotes
282 : else
283 : {
284 0 : while (pDivision)
285 : {
286 0 : if (pDivision->GetEndnoteType() == FN_DONTCARE)
287 0 : break;
288 0 : if (m_nType == FN_DIVISIONGROUP)
289 0 : pDivision = pDivision->GetPreviousInGroup();
290 : else
291 0 : pDivision = pDivision->GetPreviousDivisionWithContents();
292 : }
293 : }
294 0 : if (pDivision)
295 0 : return pDivision;
296 0 : return NULL;
297 : }
298 :
299 : /**
300 : * @descr Get division which endnote table contains current endnote content, copy from lwp source code
301 : */
302 0 : LwpDocument* LwpFootnote::GetEndnoteDivision(LwpDocument* pPossible)
303 : {
304 0 : LwpDocument* pDivision = pPossible;
305 : sal_uInt16 nDivType;
306 :
307 : // In case we have multiple endnote divisions, walk backwards until
308 : // we find one.
309 0 : while (pDivision)
310 : {
311 : // Do we already have the right division?
312 0 : nDivType = pDivision->GetEndnoteType();
313 0 : if (nDivType == m_nType)
314 0 : return pDivision;
315 : // When we hit the first non-endnote division, stop looking.
316 : // -- SDC 10/8/96
317 0 : if (nDivType == FN_DONTCARE)
318 0 : break;
319 0 : pDivision = pDivision->GetPreviousDivision();
320 : }
321 0 : return NULL;
322 : }
323 :
324 : /**
325 : * @descr Get footnote table class name
326 : */
327 0 : OUString LwpFootnote::GetTableClass()
328 : {
329 0 : OUString strClassName;
330 0 : switch (GetType() & FN_MASK_BASE)
331 : {
332 : case FN_BASE_FOOTNOTE:
333 : {
334 0 : strClassName = A2OUSTR(STR_DivisionFootnote);
335 0 : break;
336 : }
337 : case FN_BASE_DOCUMENT:
338 : {
339 0 : strClassName = A2OUSTR(STR_DocumentEndnote);
340 0 : break;
341 : }
342 : case FN_BASE_DIVISION:
343 : {
344 0 : strClassName = A2OUSTR(STR_DivisionEndnote);
345 0 : break;
346 : }
347 : case FN_BASE_DIVISIONGROUP:
348 : {
349 0 : strClassName = A2OUSTR(STR_DivisionGroupEndnote);
350 0 : break;
351 : }
352 : }
353 0 : return strClassName;
354 : }
355 :
356 : /**
357 : * @descr Find footnote tablelayout, copy from lwp source code
358 : */
359 0 : LwpEnSuperTableLayout* LwpFootnote::FindFootnoteTableLayout()
360 : {
361 0 : LwpDocument* pDivision = GetFootnoteTableDivision();
362 0 : if(!pDivision)
363 0 : return NULL;
364 :
365 0 : LwpFoundry* pFoundry = pDivision->GetFoundry();
366 0 : OUString strClassName = GetTableClass();
367 0 : if(strClassName.isEmpty() )
368 0 : return NULL;
369 :
370 0 : LwpContent* pContent = NULL;
371 :
372 0 : while ((pContent = pFoundry->EnumContents(pContent)) != NULL)
373 0 : if (pContent->IsTable() && (strClassName.equals(pContent->GetClassName())) &&
374 0 : pContent->IsActive() && pContent->GetLayout(NULL))
375 : {
376 : // Found it!
377 : return (LwpEnSuperTableLayout *)
378 0 : ((LwpTable*)pContent)->GetSuperTableLayout();
379 : }
380 :
381 0 : return NULL;
382 : }
383 :
384 : /**
385 : * @descr Find footnote contents
386 : */
387 2 : LwpContent* LwpFootnote::FindFootnoteContent()
388 : {
389 2 : 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 2 : if(pContent && pContent->GetLayout(NULL))
393 2 : return pContent;
394 :
395 0 : LwpCellLayout* pCellLayout = GetCellLayout();
396 0 : if(pCellLayout)
397 : {
398 0 : pContent = dynamic_cast<LwpContent*>(pCellLayout->GetContent()->obj());
399 : }
400 :
401 0 : return pContent;
402 : }
403 :
404 1 : LwpFootnoteTable::LwpFootnoteTable(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
405 1 : : LwpTable(objHdr, pStrm)
406 : {
407 1 : }
408 :
409 1 : void LwpFootnoteTable::Read()
410 : {
411 1 : LwpTable::Read();
412 1 : m_pObjStrm->SkipExtra();
413 1 : }
414 :
415 : /**
416 : * @descr Read footnote number options information
417 : */
418 16 : void LwpFootnoteNumberOptions::Read(LwpObjectStream *pObjStrm)
419 : {
420 16 : m_nFlag = pObjStrm->QuickReaduInt16();
421 16 : m_nStartingNumber = pObjStrm->QuickReaduInt16();
422 16 : m_LeadingText.Read(pObjStrm);
423 16 : m_TrailingText.Read(pObjStrm);
424 16 : pObjStrm->SkipExtra();
425 16 : }
426 :
427 : /**
428 : * @descr Read footnote seperator options information
429 : */
430 8 : void LwpFootnoteSeparatorOptions::Read(LwpObjectStream *pObjStrm)
431 : {
432 8 : m_nFlag = pObjStrm->QuickReaduInt16();
433 8 : m_nLength = pObjStrm->QuickReaduInt32();
434 8 : m_nIndent = pObjStrm->QuickReaduInt32();
435 8 : m_nAbove = pObjStrm->QuickReaduInt32();
436 8 : m_nBelow = pObjStrm->QuickReaduInt32();
437 8 : m_BorderStuff.Read(pObjStrm);
438 8 : pObjStrm->SkipExtra();
439 8 : }
440 :
441 :
442 4 : LwpFootnoteOptions::LwpFootnoteOptions(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
443 4 : : LwpObject(objHdr, pStrm)
444 : {
445 4 : }
446 :
447 8 : LwpFootnoteOptions::~LwpFootnoteOptions()
448 : {
449 :
450 8 : }
451 :
452 : /**
453 : * @descr Register footnote options object
454 : */
455 4 : void LwpFootnoteOptions::Read()
456 : {
457 4 : m_nFlag = m_pObjStrm->QuickReaduInt16();
458 4 : m_FootnoteNumbering.Read(m_pObjStrm);
459 4 : m_EndnoteDivisionNumbering.Read(m_pObjStrm);
460 4 : m_EndnoteDivisionGroupNumbering.Read(m_pObjStrm);
461 4 : m_EndnoteDocNumbering.Read(m_pObjStrm);
462 4 : m_FootnoteSeparator.Read(m_pObjStrm);
463 4 : m_FootnoteContinuedSeparator.Read(m_pObjStrm);
464 4 : m_ContinuedOnMessage.Read(m_pObjStrm);
465 4 : m_ContinuedFromMessage.Read(m_pObjStrm);
466 4 : m_pObjStrm->SkipExtra();
467 4 : }
468 :
469 : /**
470 : * @descr Register footnote options style
471 : */
472 4 : void LwpFootnoteOptions::RegisterStyle()
473 : {
474 4 : RegisterFootnoteStyle();
475 4 : RegisterEndnoteStyle();
476 4 : }
477 :
478 : /**
479 : * @descr Register footnote configuration information
480 : */
481 4 : void LwpFootnoteOptions::RegisterFootnoteStyle()
482 : {
483 4 : XFFootnoteConfig* pFootnoteConfig = new XFFootnoteConfig();
484 4 : pFootnoteConfig->SetStartValue(m_FootnoteNumbering.GetStartingNumber() -1);
485 4 : pFootnoteConfig->SetNumPrefix(m_FootnoteNumbering.GetLeadingText());
486 4 : pFootnoteConfig->SetNumSuffix(m_FootnoteNumbering.GetTrailingText());
487 4 : if(m_FootnoteNumbering.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE)
488 : {
489 0 : pFootnoteConfig->SetRestartOnPage();
490 : }
491 4 : if(GetContinuedFrom())
492 : {
493 0 : pFootnoteConfig->SetMessageFrom(GetContinuedFromMessage());
494 : }
495 4 : if(GetContinuedOn())
496 : {
497 0 : pFootnoteConfig->SetMessageOn(GetContinuedOnMessage());
498 : }
499 :
500 4 : pFootnoteConfig->SetMasterPage( m_strMasterPage);
501 4 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
502 4 : pXFStyleManager->SetFootnoteConfig(pFootnoteConfig);
503 :
504 4 : }
505 :
506 : /**
507 : * @descr Register endnote configuration information
508 : */
509 4 : void LwpFootnoteOptions::RegisterEndnoteStyle()
510 : {
511 4 : XFEndnoteConfig* pEndnoteConfig = new XFEndnoteConfig();
512 4 : pEndnoteConfig->SetStartValue(m_EndnoteDocNumbering.GetStartingNumber() -1);
513 4 : OUString message = m_EndnoteDocNumbering.GetLeadingText();
514 4 : if(message.isEmpty())
515 : {
516 4 : message = A2OUSTR("[");//default prefix
517 : }
518 4 : pEndnoteConfig->SetNumPrefix(message);
519 4 : message = m_EndnoteDocNumbering.GetTrailingText();
520 4 : if(message.isEmpty())
521 : {
522 4 : message = A2OUSTR("]");//default suffix
523 : }
524 4 : pEndnoteConfig->SetNumSuffix(message);
525 4 : if(m_EndnoteDocNumbering.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE)
526 : {
527 0 : pEndnoteConfig->SetRestartOnPage();
528 : }
529 :
530 4 : pEndnoteConfig->SetMasterPage( m_strMasterPage);
531 :
532 4 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
533 4 : pXFStyleManager->SetEndnoteConfig(pEndnoteConfig);
534 4 : }
535 :
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 A2OUSTR(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 A2OUSTR(STRID_FOOTCONTINUEDFROM);
561 : }
562 :
563 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|