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