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 : * LwpStory:
59 : 1. Word Pro object for paragraph list;
60 : 2. the content of layout object
61 : ************************************************************************/
62 : /*************************************************************************
63 : * Change History
64 : Jan 2005 Created
65 : ************************************************************************/
66 : #include "lwpglobalmgr.hxx"
67 : #include "lwpstory.hxx"
68 : #include "xfilter/xfstylemanager.hxx"
69 :
70 96 : LwpStory::LwpStory(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
71 : : LwpContent(objHdr, pStrm)
72 : , m_bPMModified(false)
73 : , m_pCurrentLayout(NULL)
74 : , m_pTabLayout(NULL)
75 : , m_bDropcap(false)
76 96 : , m_pHyperlinkMgr(new LwpHyperlinkMgr)
77 192 : , m_pXFContainer(NULL)
78 : {
79 96 : }
80 :
81 288 : LwpStory::~LwpStory()
82 : {
83 96 : delete m_pHyperlinkMgr;
84 192 : }
85 :
86 96 : void LwpStory::Read()
87 : {
88 96 : LwpContent::Read();
89 96 : m_ParaList.Read(m_pObjStrm);
90 96 : m_FirstParaStyle.ReadIndexed(m_pObjStrm);
91 96 : m_pObjStrm->SkipExtra();
92 96 : }
93 :
94 : #include "lwppara.hxx"
95 : #include "lwpobjfactory.hxx"
96 : /**************************************************************************
97 : * @descr: Convert all the contents in current story
98 : * @param:
99 : * @param:
100 : * @return:
101 : **************************************************************************/
102 40 : void LwpStory::XFConvert(XFContentContainer* pCont)
103 : {
104 : //process frame which anchor frame
105 40 : XFConvertFrameInFrame(pCont);
106 : //process para list
107 40 : XFContentContainer* pParaCont = pCont;
108 40 : LwpPara* pPara = dynamic_cast<LwpPara*> ( GetFirstPara().obj().get() );
109 372 : while(pPara)
110 : {
111 292 : pPara->SetFoundry(m_pFoundry);
112 292 : pPara->XFConvert(pParaCont);
113 :
114 : //Get the xfcontainer for the next para
115 292 : pParaCont = pPara->GetXFContainer();
116 292 : pPara = dynamic_cast<LwpPara*> ( pPara->GetNext().obj().get() );
117 : }
118 :
119 : //process frame which anchor is to cell after converter all the para
120 40 : XFConvertFrameInCell(pCont);
121 40 : XFConvertFrameInHeaderFooter(pCont);
122 :
123 : //Release Lwp Objects
124 40 : LwpPara* pCur = dynamic_cast<LwpPara*> (GetFirstPara().obj().get());
125 : LwpPara* pNext;
126 372 : while(pCur)
127 : {
128 292 : pCur->Release();
129 292 : pNext = dynamic_cast<LwpPara*> ( pCur->GetNext().obj().get() );
130 292 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
131 292 : LwpObjectFactory* pObjMgr = pGlobal->GetLwpObjFactory();
132 292 : pObjMgr->ReleaseObject(pCur->GetObjectID());
133 292 : pCur = pNext;
134 : }
135 40 : }
136 :
137 114 : void LwpStory::RegisterStyle()
138 : {
139 114 : LwpPara* pPara = dynamic_cast<LwpPara*>( GetFirstPara().obj().get() );
140 744 : while(pPara)
141 : {
142 518 : pPara->SetFoundry(m_pFoundry);
143 518 : pPara->RegisterStyle();
144 516 : pPara = dynamic_cast<LwpPara*>(pPara->GetNext().obj().get());
145 : }
146 112 : }
147 :
148 6 : void LwpStory::Parse(IXFStream* pOutputStream)
149 : {
150 6 : m_pXFContainer = new XFContentContainer;
151 6 : XFConvert(m_pXFContainer);
152 6 : m_pXFContainer->ToXml(pOutputStream);
153 6 : delete m_pXFContainer;
154 6 : m_pXFContainer = NULL;
155 :
156 : //It seems that, currently, we do not need to process the child story
157 : /*LwpObject* pChildStory = GetFirstStory()->obj();
158 : if(pChildStory)
159 : {
160 : pChildStory->SetFoundry(m_pFoundry);
161 : pChildStory->Parse(pOutputStream);
162 : }*/
163 :
164 : //Don't process the next story
165 : /* LwpObject* pNextStory = GetNextStory()->obj();
166 : if(pNextStory)
167 : {
168 : pNextStory->SetFoundry(m_pFoundry);
169 : pNextStory->Parse(pOutputStream);
170 : }*/
171 :
172 6 : }
173 :
174 : #include "lwppagelayout.hxx"
175 : /**************************************************************************
176 : * @descr: Set current page layout. If pPageLayout is a mirro page layout,
177 : use odd child page layout as current page layout.
178 : * @param:
179 : * @param:
180 : * @return:
181 : **************************************************************************/
182 8 : void LwpStory::SetCurrentLayout(LwpPageLayout *pPageLayout)
183 : {
184 8 : LwpPageLayout* pLayout = pPageLayout->GetOddChildLayout();
185 8 : if(pLayout)
186 : {
187 0 : m_pCurrentLayout = pLayout;
188 0 : m_pTabLayout = pLayout;
189 : }
190 : else
191 : {
192 8 : m_pCurrentLayout = pPageLayout;
193 8 : m_pTabLayout = pPageLayout;
194 : }
195 8 : m_bPMModified = true;
196 8 : }
197 :
198 0 : void LwpStory::AddPageLayout(LwpPageLayout * pObject)
199 : {
200 0 : m_LayoutList.push_back(pObject);
201 0 : }
202 : /**************************************************************************
203 : * @descr: Get the next page layout relative to m_pCurrentLayout
204 : * @param:
205 : * @param:
206 : * @return:
207 : **************************************************************************/
208 0 : LwpPageLayout* LwpStory::GetNextPageLayout()
209 : {
210 0 : std::vector<LwpPageLayout*>::iterator it;
211 0 : for( it = m_LayoutList.begin(); it != m_LayoutList.end(); ++it )
212 : {
213 0 : if(m_pCurrentLayout == *it)
214 : {
215 0 : if((it+1) !=m_LayoutList.end())
216 : {
217 0 : return *(it+1);
218 : }
219 : }
220 : }
221 0 : return NULL;
222 : }
223 : /**************************************************************************
224 : * @descr: Sort the pagelayout according to their position
225 : * @param:
226 : * @param:
227 : * @return:
228 : **************************************************************************/
229 8 : void LwpStory::SortPageLayout()
230 : {
231 : //Get all the pagelayout and store in list
232 8 : std::vector<LwpPageLayout*> aLayoutList;
233 8 : LwpVirtualLayout* pLayout = GetLayout(NULL);
234 24 : while(pLayout)
235 : {
236 8 : if(pLayout->IsPage())
237 : {
238 8 : LwpLayout::UseWhenType eSectionType = static_cast<LwpPageLayout*>(pLayout)->GetUseWhenType();
239 : //for mirror page, the child is pagelayout
240 8 : LwpVirtualLayout* pParent = pLayout->GetParentLayout();
241 8 : if(eSectionType != LwpLayout::StartWithinColume && pParent && !pParent->IsPage())
242 : {
243 8 : aLayoutList.push_back(static_cast<LwpPageLayout*>(pLayout));
244 : }
245 : }
246 8 : pLayout = GetLayout(pLayout);
247 : }
248 : // sort the pagelayout according to their position
249 8 : std::vector<LwpPageLayout*>::iterator aIt;
250 8 : if (!aLayoutList.empty())
251 : {
252 8 : for( aIt = aLayoutList.begin(); aIt != aLayoutList.end() -1; ++aIt)
253 : {
254 0 : for( std::vector<LwpPageLayout*>::iterator bIt = aIt +1; bIt != aLayoutList.end(); ++bIt )
255 : {
256 0 : if(**aIt < **bIt)
257 : {
258 0 : continue;
259 : }
260 : else
261 : {
262 0 : LwpPageLayout* pTemp = *aIt;
263 0 : *aIt = *bIt;
264 0 : *bIt = pTemp;
265 : }
266 : }
267 : }
268 : }
269 :
270 : //put all the sorted layouts into list
271 8 : m_LayoutList.clear();
272 :
273 16 : for( aIt = aLayoutList.begin(); aIt != aLayoutList.end(); ++aIt)
274 : {
275 8 : m_LayoutList.push_back(*aIt);
276 8 : }
277 8 : }
278 :
279 : /**************************************************************************
280 : * @descr: whether need create a new section and reset column in current page layout
281 : * @param:
282 : * @param:
283 : * @return: sal_True if need create a new section
284 : **************************************************************************/
285 8 : bool LwpStory::IsNeedSection()
286 : {
287 8 : bool bColumns = false;
288 8 : bool bNewSection = false;
289 8 : if(m_pCurrentLayout)
290 : {
291 8 : if(m_pCurrentLayout->HasColumns())
292 : {
293 : //get the following pagelayout and its type
294 0 : bColumns = true;
295 0 : LwpPageLayout* pNextLayout = GetNextPageLayout();
296 0 : if(pNextLayout)
297 : {
298 : //get layout type
299 0 : LwpLayout::UseWhenType eWhenType = pNextLayout->GetUseWhenType();
300 0 : switch(eWhenType)
301 : {
302 : case LwpLayout::StartWithinColume://not support now
303 : case LwpLayout::StartWithinPage:
304 : {
305 0 : bColumns =false;
306 0 : bNewSection = true;
307 0 : break;
308 : }
309 : case LwpLayout::StartOnNextPage:
310 : case LwpLayout::StartOnOddPage://not support now
311 : case LwpLayout::StartOnEvenPage://not support now
312 : {
313 0 : bColumns =true;
314 0 : bNewSection = false;
315 0 : break;
316 : }
317 : default:
318 0 : break;
319 : }
320 : }
321 :
322 : //if bColumns is ture, the page layout doesn't need columns, set the xfcolumns to NULL in page master
323 0 : if(!bColumns)
324 : {
325 0 : m_pCurrentLayout->ResetXFColumns();
326 : }
327 : }
328 8 : SetPMModified(false);
329 : }
330 8 : return bNewSection;
331 : }
332 : /**************************************************************************
333 : * @descr: process frame which anchor type is to cell
334 : * @param:
335 : * @param:
336 : * @return:
337 : **************************************************************************/
338 40 : void LwpStory::XFConvertFrameInCell(XFContentContainer* pCont)
339 : {
340 40 : LwpVirtualLayout* pLayout = GetLayout(NULL);
341 120 : while(pLayout)
342 : {
343 40 : LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead().obj().get());
344 92 : while(pFrameLayout)
345 : {
346 :
347 : //if(pFrameLayout->IsAnchorCell())
348 12 : if(pFrameLayout->IsAnchorCell() && pFrameLayout->HasContent())
349 : {
350 : //get the first xfpara
351 : rtl::Reference<XFContent> first(
352 0 : pCont->FindFirstContent(enumXFContentPara));
353 0 : XFContentContainer* pXFFirtPara = static_cast<XFContentContainer*>(first.get());
354 0 : if(pXFFirtPara)
355 0 : pFrameLayout->XFConvert(pXFFirtPara);
356 : }
357 12 : pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext().obj().get());
358 : }
359 40 : pLayout = GetLayout(pLayout);
360 : }
361 40 : }
362 :
363 : /**************************************************************************
364 : * @descr: process frame which anchor type is to page
365 : * @param:
366 : * @param:
367 : * @return:
368 : **************************************************************************/
369 6 : void LwpStory::XFConvertFrameInPage(XFContentContainer* pCont)
370 : {
371 6 : LwpVirtualLayout* pLayout = GetLayout(NULL);
372 18 : while(pLayout)
373 : {
374 6 : LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead().obj().get());
375 24 : while(pFrameLayout)
376 : {
377 24 : if((pFrameLayout->IsAnchorPage()
378 12 : &&(pFrameLayout->IsFrame()
379 12 : ||pFrameLayout->IsSuperTable()
380 12 : ||pFrameLayout->IsGroupHead())))
381 : {
382 0 : pFrameLayout->XFConvert(pCont);
383 : }
384 12 : pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext().obj().get());
385 : }
386 6 : pLayout = GetLayout(pLayout);
387 : }
388 6 : }
389 : /**************************************************************************
390 : * @descr: process frame which anchor type is to frame
391 : * @param:
392 : * @param:
393 : * @return:
394 : **************************************************************************/
395 40 : void LwpStory::XFConvertFrameInFrame(XFContentContainer* pCont)
396 : {
397 40 : LwpVirtualLayout* pLayout = GetLayout(NULL);
398 120 : while(pLayout)
399 : {
400 40 : LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead().obj().get());
401 92 : while(pFrameLayout)
402 : {
403 12 : if(pFrameLayout->IsAnchorFrame())
404 : {
405 0 : pFrameLayout->XFConvert(pCont);
406 : }
407 12 : pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext().obj().get());
408 : }
409 40 : pLayout = GetLayout(pLayout);
410 : }
411 40 : }
412 : /**************************************************************************
413 : * @descr: process frame which anchor type is to page and the frame is contained by header or footer
414 : * @param:
415 : * @param:
416 : * @return:
417 : **************************************************************************/
418 40 : void LwpStory::XFConvertFrameInHeaderFooter(XFContentContainer* pCont)
419 : {
420 40 : LwpVirtualLayout* pLayout = GetLayout(NULL);
421 120 : while(pLayout)
422 : {
423 40 : LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead().obj().get());
424 92 : while(pFrameLayout)
425 : {
426 12 : if(pFrameLayout->IsAnchorPage() && (pLayout->IsHeader() || pLayout->IsFooter()))
427 : {
428 : //The frame must be included by <text:p>
429 : rtl::Reference<XFContent> first(
430 0 : pCont->FindFirstContent(enumXFContentPara));
431 0 : XFContentContainer* pXFFirtPara = static_cast<XFContentContainer*>(first.get());
432 0 : if(pXFFirtPara)
433 0 : pFrameLayout->XFConvert(pXFFirtPara);
434 : }
435 12 : pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext().obj().get());
436 : }
437 40 : pLayout = GetLayout(pLayout);
438 : }
439 40 : }
440 :
441 0 : void LwpStory::AddXFContent(XFContent* pContent)
442 : {
443 0 : if(m_pXFContainer)
444 0 : m_pXFContainer->Add(pContent);
445 0 : }
446 :
447 0 : XFContentContainer* LwpStory::GetXFContent()
448 : {
449 0 : if(m_pXFContainer)
450 0 : return m_pXFContainer;
451 : else
452 0 : return NULL;
453 : }
454 :
455 4 : LwpPara* LwpStory::GetLastParaOfPreviousStory()
456 : {
457 4 : LwpVirtualLayout* pVLayout = this->GetLayout(NULL);
458 4 : if (pVLayout)
459 : {
460 2 : return pVLayout->GetLastParaOfPreviousStory();
461 : }
462 :
463 2 : return NULL;
464 : }
465 : /**************************************************************************
466 : * @descr: get text from story
467 : * @param:
468 : * @param:
469 : * @return:
470 : **************************************************************************/
471 0 : OUString LwpStory::GetContentText(bool bAllText)
472 : {
473 0 : if (bAllText)//convert all text fribs
474 : {
475 0 : OUString sText("");
476 : //process para list
477 0 : LwpPara* pPara = dynamic_cast<LwpPara*>(GetFirstPara().obj().get());
478 0 : while (pPara)
479 : {
480 0 : pPara->SetFoundry(m_pFoundry);
481 0 : sText += pPara->GetContentText(true);
482 0 : pPara = dynamic_cast<LwpPara*>(pPara->GetNext().obj().get());
483 : }
484 0 : return sText;
485 : }
486 : else //only the first text frib
487 : {
488 0 : rtl::Reference<LwpObject> pObj = GetFirstPara().obj();
489 0 : if(pObj.is())
490 : {
491 0 : LwpPara* pPara = dynamic_cast<LwpPara*>(pObj.get());
492 0 : if (!pPara || pPara->GetNext().obj() != NULL)
493 0 : return OUString("");
494 0 : pPara->SetFoundry(m_pFoundry);
495 0 : return pPara->GetContentText();
496 : }
497 0 : return OUString("");
498 : }
499 :
500 : }
501 0 : OUString LwpStory::RegisterFirstFribStyle()
502 : {
503 0 : LwpPara* pPara = dynamic_cast<LwpPara*>(GetFirstPara().obj().get());
504 0 : if (!pPara)
505 0 : return OUString("");
506 0 : pPara->SetFoundry(m_pFoundry);
507 0 : LwpFribPtr& rFribs = pPara->GetFribs();
508 0 : LwpFrib* pFirstFrib = rFribs.GetFribs();
509 0 : pFirstFrib->RegisterStyle(m_pFoundry);
510 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
511 0 : XFTextStyle* pBaseStyle = pXFStyleManager->FindTextStyle(pFirstFrib->GetStyleName());
512 0 : if (pBaseStyle == NULL)
513 0 : return OUString("");
514 0 : XFTextStyle* pStyle = new XFTextStyle;
515 0 : *pStyle = *pBaseStyle;
516 0 : OUString sName = "Ruby" + pFirstFrib->GetStyleName();
517 0 : pStyle->SetStyleName(sName);
518 0 : pXFStyleManager->AddStyle(pStyle);
519 0 : return sName;
520 : }
521 :
522 12 : bool LwpStory::IsBullStyleUsedBefore(const OUString& rStyleName, const sal_uInt8& nPos)
523 : {
524 12 : std::vector <NamePosPair>::reverse_iterator rIter;
525 12 : for (rIter = m_vBulletStyleNameList.rbegin(); rIter != m_vBulletStyleNameList.rend(); ++rIter)
526 : {
527 6 : OUString aName = (*rIter).first;
528 6 : sal_uInt8 nPosition = (*rIter).second;
529 6 : if (aName == rStyleName && nPosition == nPos)
530 : {
531 6 : return true;
532 : }
533 0 : }
534 6 : return false;
535 : }
536 :
537 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|