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 : * For LWP filter architecture prototype
59 : ************************************************************************/
60 : /*************************************************************************
61 : * Change History
62 : Jan 2005 Created
63 : ************************************************************************/
64 :
65 : #include "lwpfoundry.hxx"
66 : #include "lwpfilehdr.hxx"
67 : #include "lwpdoc.hxx"
68 : #include "lwpmarker.hxx"
69 : #include "lwpholder.hxx"
70 : #include "lwpbulletstylemgr.hxx"
71 : #include "lwpcontent.hxx"
72 : #include "lwpvpointer.hxx"
73 : #include "lwpsection.hxx"
74 : #include "lwpcharacterstyle.hxx"
75 : #include "lwpglobalmgr.hxx"
76 :
77 0 : LwpFoundry::LwpFoundry(LwpObjectStream *pStrm, LwpDocument* pDoc)
78 : : m_pDoc(pDoc)
79 : , m_bRegisteredAll(false)
80 : , m_pPieceMgr(NULL)
81 0 : , m_pStyleMgr(NULL)
82 : {
83 0 : Read(pStrm);
84 0 : m_pDropcapMgr = new LwpDropcapMgr;
85 0 : m_pBulletStyleMgr = new LwpBulletStyleMgr();
86 0 : m_pBulletStyleMgr->SetFoundry(this);
87 0 : }
88 :
89 0 : LwpFoundry::~LwpFoundry()
90 : {
91 0 : if(m_pPieceMgr)
92 : {
93 0 : delete m_pPieceMgr;
94 : }
95 0 : if(m_pStyleMgr)
96 : {
97 0 : delete m_pStyleMgr;
98 : }
99 0 : if (m_pDropcapMgr)
100 0 : delete m_pDropcapMgr;
101 0 : if (m_pBulletStyleMgr)
102 : {
103 0 : delete m_pBulletStyleMgr;
104 : }
105 0 : }
106 :
107 0 : void LwpFoundry::Read(LwpObjectStream *pStrm)
108 : {
109 0 : if (!m_pDoc->IsChildDoc())
110 : {
111 0 : m_VerMgr.Read(pStrm);
112 : }
113 0 : m_ObjMgr.Read(pStrm);
114 :
115 0 : m_MarkerHead.ReadIndexed(pStrm);
116 0 : m_FootnoteMgr.ReadIndexed(pStrm);
117 :
118 0 : m_NumMgr.Read(pStrm);
119 0 : m_BulMgr.Read(pStrm);
120 :
121 0 : m_SectionList.Read(pStrm);
122 0 : m_Layout.ReadIndexed(pStrm);
123 :
124 0 : ReadStyles(pStrm);
125 :
126 0 : m_BookMarkHead.ReadIndexed(pStrm);
127 0 : m_DdeLinkHead.ReadIndexed(pStrm);
128 0 : m_DirtBagHead.ReadIndexed(pStrm);
129 0 : m_NamedOutlineSeqHead.ReadIndexed(pStrm);
130 :
131 0 : m_EnumLayoutHead.ReadIndexed(pStrm);
132 0 : m_EnumLayoutTail.ReadIndexed(pStrm);
133 0 : m_NamedObjects.ReadIndexed(pStrm);
134 :
135 0 : m_nLastClickHere = pStrm->QuickReaduInt32();
136 0 : m_SmartTextMgr.ReadIndexed(pStrm);
137 :
138 0 : m_ContentMgr.Read(pStrm);
139 0 : m_FontMgr.Read(pStrm);
140 :
141 0 : if (!m_pDoc->IsChildDoc() && LwpFileHeader::m_nFileRevision >= 0x000B)
142 : {
143 0 : m_pPieceMgr = new LwpPieceManager();
144 :
145 0 : m_pPieceMgr->Read(pStrm);
146 : }
147 :
148 0 : if( LwpFileHeader::m_nFileRevision >= 0x000B)
149 : {
150 0 : m_DftDropCapStyle.ReadIndexed(pStrm);
151 : }
152 0 : if( LwpFileHeader::m_nFileRevision >= 0x000F)
153 : {
154 0 : m_DftHeaderStyle.ReadIndexed(pStrm);
155 0 : m_DftFooterStyle.ReadIndexed(pStrm);
156 : }
157 0 : pStrm->SkipExtra();
158 :
159 0 : m_pStyleMgr = new LwpStyleManager();
160 0 : m_pStyleMgr->SetFoundry(this);
161 0 : }
162 :
163 0 : void LwpFoundry::ReadStyles(LwpObjectStream *pStrm)
164 : {
165 0 : m_TextStyle.ReadIndexed(pStrm);
166 0 : m_DefaultTextStyle.ReadIndexed(pStrm);
167 0 : m_DefaultClickStyle.ReadIndexed(pStrm);
168 0 : m_PageStyle.ReadIndexed(pStrm);
169 0 : m_FrameStyle.ReadIndexed(pStrm);
170 :
171 0 : m_TableStyle.ReadIndexed(pStrm);
172 0 : m_CellStyle.ReadIndexed(pStrm);
173 0 : m_DftFrameStyle.ReadIndexed(pStrm);
174 0 : m_DftPageStyle.ReadIndexed(pStrm);
175 0 : m_DftTableStyle.ReadIndexed(pStrm);
176 :
177 0 : m_DftCellStyle.ReadIndexed(pStrm);
178 0 : m_DftColumnStyle.ReadIndexed(pStrm);
179 0 : m_DftLeftColumnStyle.ReadIndexed(pStrm);
180 0 : m_DftRighColumnStyle.ReadIndexed(pStrm);
181 :
182 0 : }
183 :
184 : #include "xfilter/xfstylemanager.hxx"
185 : #include "lwplayout.hxx"
186 :
187 0 : void LwpFoundry::RegisterAllLayouts()
188 : {
189 0 : if (m_bRegisteredAll)
190 : {
191 : OSL_FAIL("recursive LwpFoundry::RegisterAllLayouts!\n");
192 0 : return;
193 : }
194 :
195 0 : m_bRegisteredAll = true;
196 :
197 : //Register CellStyle
198 0 : LwpObject* pStyle = m_CellStyle.obj();
199 0 : if( pStyle )
200 : {
201 0 : pStyle->SetFoundry(this);
202 0 : pStyle->RegisterStyle();
203 : }
204 :
205 : //register content page layout list: Layout
206 0 : pStyle = m_Layout.obj();
207 0 : if( pStyle )
208 : {
209 0 : pStyle->SetFoundry(this);
210 0 : pStyle->RegisterStyle();
211 : }
212 :
213 : //Register page style layout list: PageStyle, such as "Default Page"
214 0 : pStyle = m_PageStyle.obj();
215 0 : if( pStyle )
216 : {
217 0 : pStyle->SetFoundry(this);
218 0 : pStyle->RegisterStyle();
219 : }
220 :
221 : //Register FrameStyle
222 0 : pStyle = m_FrameStyle.obj();
223 0 : if( pStyle )
224 : {
225 0 : pStyle->SetFoundry(this);
226 0 : pStyle->RegisterStyle();
227 : }
228 :
229 : }
230 :
231 0 : LwpBookMark* LwpFoundry::GetBookMark(LwpObjectID objMarker)
232 : {
233 : LwpDLVListHeadHolder* pHeadHolder= static_cast
234 0 : <LwpDLVListHeadHolder*>(m_BookMarkHead.obj());
235 0 : LwpObjectID* pObjID = pHeadHolder->GetHeadID();
236 : LwpBookMark* pBookMark;
237 0 : if (pObjID)
238 0 : pBookMark = static_cast<LwpBookMark*>(pObjID->obj());
239 : else
240 0 : return NULL;
241 :
242 0 : while (pBookMark)
243 : {
244 0 : if (pBookMark->IsRightMarker(objMarker))
245 0 : return pBookMark;
246 0 : pObjID = pBookMark->GetNext();
247 0 : if (pObjID)
248 0 : pBookMark = static_cast<LwpBookMark*>(pObjID->obj());
249 : else
250 0 : return NULL;
251 : }
252 0 : return NULL;
253 : }
254 :
255 : /**
256 : * @descr: Get next content
257 : *
258 : */
259 0 : LwpContent* LwpFoundry::EnumContents(LwpContent * pContent)
260 : {
261 0 : return GetContentManager()->EnumContents(pContent);
262 : }
263 :
264 : /**
265 : * @descr: Get next section
266 : *
267 : */
268 0 : LwpSection* LwpFoundry::EnumSections(LwpSection * pSection)
269 : {
270 0 : return static_cast<LwpSection*>(m_SectionList.Enumerate(pSection));
271 : }
272 :
273 : /**
274 : * @descr: Get default text style id
275 : *
276 : */
277 0 : LwpObjectID * LwpFoundry::GetDefaultTextStyle()
278 : {
279 0 : LwpVersionedPointer * pPointer = static_cast<LwpVersionedPointer *>(m_DefaultTextStyle.obj());
280 0 : if (!pPointer)
281 0 : return NULL;
282 :
283 0 : return pPointer->GetPointer();
284 : }
285 :
286 : /**
287 : * @descr: Get paragraph style object id according to its style name
288 : *
289 : */
290 0 : LwpObjectID * LwpFoundry::FindParaStyleByName(const OUString& name)
291 : {
292 : //Register all text styles: para styles, character styles
293 0 : LwpDLVListHeadHolder* pParaStyleHolder = static_cast<LwpDLVListHeadHolder*>(GetTextStyleHead()->obj());
294 0 : if(pParaStyleHolder)
295 : {
296 0 : LwpTextStyle* pParaStyle = static_cast<LwpTextStyle*> (pParaStyleHolder->GetHeadID()->obj());
297 0 : while(pParaStyle)
298 : {
299 0 : OUString strName = pParaStyle->GetName()->str();
300 0 : if(strName == name)
301 0 : return pParaStyle->GetObjectID();
302 0 : pParaStyle = static_cast<LwpTextStyle*>(pParaStyle->GetNext()->obj());
303 0 : }
304 : }
305 :
306 0 : return NULL;
307 : }
308 :
309 : /**
310 : * @descr: Get style name registered according the original style name
311 : *
312 : */
313 0 : OUString LwpFoundry::FindActuralStyleName(const OUString& name)
314 : {
315 0 : LwpObjectID* pID = FindParaStyleByName(name);
316 0 : if(pID)
317 : {
318 0 : IXFStyle* pStyle = GetStyleManager()->GetStyle(*pID);
319 0 : if(pStyle)
320 : {
321 0 : return pStyle->GetStyleName();
322 : }
323 : }
324 :
325 0 : return name;
326 : }
327 :
328 0 : void LwpVersionManager::Read(LwpObjectStream *pStrm)
329 : {
330 : // TODO: skip the data for prototype
331 0 : Skip(pStrm);
332 0 : }
333 :
334 0 : void LwpVersionManager::Skip(LwpObjectStream *pStrm)
335 : {
336 0 : pStrm->QuickReaduInt32();
337 0 : sal_uInt16 Count = pStrm->QuickReaduInt16();
338 :
339 0 : while(Count--)
340 : {
341 0 : sal_uInt32 tag = pStrm->QuickReaduInt32();
342 0 : switch(tag)
343 : {
344 : case TAG_USER_VERSION:
345 : // TODO: skip the CUserVersionControl
346 0 : pStrm->SeekRel(pStrm->QuickReaduInt16());
347 0 : break;
348 :
349 : default:
350 0 : pStrm->SeekRel(pStrm->QuickReaduInt16());
351 0 : pStrm->SkipExtra();
352 0 : break;
353 : }
354 : }
355 0 : pStrm->SkipExtra();
356 0 : }
357 :
358 0 : void LwpObjectManager::Read(LwpObjectStream *pStrm)
359 : {
360 :
361 0 : LwpObjectID dummy;
362 0 : dummy.Read(pStrm);
363 : // TODO: judge if we need to set the cDelta by the dummy id
364 :
365 0 : m_Division.ReadIndexed(pStrm);
366 0 : pStrm->SkipExtra();
367 0 : }
368 :
369 0 : void LwpNumberManager::Read(LwpObjectStream *pStrm)
370 : {
371 0 : m_TableRange.ReadIndexed(pStrm);
372 0 : pStrm->SkipExtra();
373 0 : }
374 :
375 0 : void LwpBulletManager::Read(LwpObjectStream *pStrm)
376 : {
377 0 : m_Head.ReadIndexed(pStrm);
378 0 : pStrm->SkipExtra();
379 0 : }
380 :
381 0 : void LwpContentManager::Read(LwpObjectStream *pStrm)
382 : {
383 0 : m_ContentList.ReadIndexed(pStrm);
384 :
385 : // TODO: to judge the file revision
386 :
387 0 : m_EnumHead.ReadIndexed(pStrm);
388 0 : m_EnumTail.ReadIndexed(pStrm);
389 :
390 0 : m_OleObjCount.ReadIndexed(pStrm);
391 :
392 0 : if( LwpFileHeader::m_nFileRevision >= 0x000B)
393 : {
394 0 : m_GrapHead.ReadIndexed(pStrm);
395 0 : m_GrapTail.ReadIndexed(pStrm);
396 0 : m_OleHead.ReadIndexed(pStrm);
397 0 : m_OleTail.ReadIndexed(pStrm);
398 : }
399 :
400 0 : pStrm->SkipExtra();
401 0 : }
402 :
403 : /**
404 : * @descr: Get next content
405 : *
406 : */
407 0 : LwpContent* LwpContentManager::EnumContents(LwpContent* pContent)
408 : {
409 0 : if(pContent)
410 0 : return pContent->GetNextEnumerated();
411 0 : LwpVersionedPointer* pPointer = static_cast<LwpVersionedPointer*>(m_EnumHead.obj());
412 0 : return pPointer ? static_cast<LwpContent*>(pPointer->GetPointer()->obj()) : NULL;
413 : }
414 :
415 0 : void LwpPieceManager::Read(LwpObjectStream *pStrm)
416 : {
417 0 : m_GeometryPieceList.ReadIndexed(pStrm);
418 0 : m_ScalePieceList.ReadIndexed(pStrm);
419 0 : m_MarginsPieceList.ReadIndexed(pStrm);
420 0 : m_ColumnsPieceList.ReadIndexed(pStrm);
421 0 : m_BorderStuffPieceList.ReadIndexed(pStrm);
422 :
423 0 : m_GutterStuffPieceList.ReadIndexed(pStrm);
424 0 : m_BackgroundStuffPieceList.ReadIndexed(pStrm);
425 0 : m_JoinStuffPieceList.ReadIndexed(pStrm);
426 0 : m_ShadowPieceList.ReadIndexed(pStrm);
427 0 : m_NumericsPieceList.ReadIndexed(pStrm);
428 :
429 0 : m_RelativityPieceList.ReadIndexed(pStrm);
430 0 : m_AlignmentPieceList.ReadIndexed(pStrm);
431 0 : m_IndentPieceList.ReadIndexed(pStrm);
432 0 : m_ParaBorderPieceList.ReadIndexed(pStrm);
433 0 : m_SpacingPieceList.ReadIndexed(pStrm);
434 :
435 0 : m_BreaksPieceList.ReadIndexed(pStrm);
436 0 : m_NumberingPieceList.ReadIndexed(pStrm);
437 0 : m_TabPieceList.ReadIndexed(pStrm);
438 0 : m_CharacterBorderPieceList.ReadIndexed(pStrm);
439 0 : m_AmikakePieceList.ReadIndexed(pStrm);
440 :
441 0 : if(pStrm->CheckExtra())
442 : {
443 0 : m_ParaBackgroundPieceList.ReadIndexed(pStrm);
444 0 : m_ExternalBorderStuffPieceList.ReadIndexed(pStrm);
445 0 : m_ExternalJoinStuffPieceList.ReadIndexed(pStrm);
446 0 : pStrm->SkipExtra();
447 : }
448 0 : }
449 :
450 0 : void LwpOrderedObjectManager::Read(LwpObjectStream *pStrm)
451 : {
452 0 : m_Head.ReadIndexed(pStrm);
453 0 : }
454 :
455 : /**
456 : * @descr: Get next orderedobject, copy from lwp source code
457 : *
458 : */
459 0 : LwpOrderedObject* LwpOrderedObjectManager::Enumerate(LwpOrderedObject * pLast)
460 : {
461 : // If Last has a next, return it.
462 0 : if(pLast && !pLast->GetNext()->IsNull())
463 0 : return static_cast<LwpOrderedObject*>(pLast->GetNext()->obj());
464 :
465 0 : LwpListList* pList = NULL;
466 0 : if(pLast)
467 : {
468 : // We're at the end of Last's list (not Liszt's list).
469 : // Start with the next active list
470 0 : pList = static_cast<LwpListList*>(pLast->GetListList()->obj());
471 0 : pList= GetNextActiveListList(pList);
472 : }
473 : else
474 : {
475 : // Start with the first active ListList
476 0 : pList = GetNextActiveListList(NULL);
477 : }
478 :
479 0 : if(pList)
480 : {
481 0 : return static_cast<LwpOrderedObject*>(pList->GetHead()->obj());
482 : }
483 :
484 0 : return NULL;
485 : }
486 :
487 : /**
488 : * @descr: Get next listlist object, copy from lwp source code
489 : *
490 : */
491 0 : LwpListList* LwpOrderedObjectManager::GetNextActiveListList(LwpListList * pLast)
492 : {
493 0 : LwpListList* pList = NULL;
494 0 : LwpContent* pContent = NULL;
495 0 : if(pLast)
496 0 : pList = static_cast<LwpListList*>(pLast->GetNext()->obj());
497 : else
498 : {
499 0 : LwpDLVListHeadHolder* pHeadHolder= static_cast<LwpDLVListHeadHolder*>(m_Head.obj());
500 0 : if(pHeadHolder)
501 : {
502 0 : pList = static_cast<LwpListList*>(pHeadHolder->GetHeadID()->obj());
503 : }
504 : }
505 :
506 0 : while(pList)
507 : {
508 0 : pContent = static_cast<LwpContent*>(pList->GetObject()->obj());
509 0 : if(pContent && pContent->HasNonEmbeddedLayouts() &&
510 0 : !pContent->IsStyleContent())
511 0 : return pList;
512 0 : pList = static_cast<LwpListList*>(pList->GetNext()->obj());
513 : }
514 0 : return NULL;
515 : }
516 :
517 0 : LwpStyleManager::LwpStyleManager()
518 0 : : m_pFoundry(0)
519 : {
520 0 : }
521 :
522 0 : LwpStyleManager::~LwpStyleManager()
523 : {
524 0 : m_StyleList.clear();
525 0 : }
526 :
527 : #include "xfilter/xfstylemanager.hxx"
528 : /*
529 : VO_PARASTYLE/VO_CHARACTERSTYLE call this method to add its created style to XFStyleManager
530 : 1. Add the style to XFStyleManager, and return the <office:styles> style name
531 : 2. Add it to LwpParaStyleMap.
532 : Prerequisite: pStyle has been created and all properties has been set to it.
533 : Return the XFStyle* added by XFStyleManager
534 : */
535 0 : IXFStyle* LwpStyleManager::AddStyle(LwpObjectID styleObjID, IXFStyle* pStyle)
536 : {
537 : assert(pStyle);
538 : //pStyle may change if same style is found in XFStyleManager
539 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
540 0 : pStyle = pXFStyleManager->AddStyle(pStyle);
541 0 : m_StyleList.insert(LwpStyleMap::value_type(styleObjID, pStyle));
542 0 : return pStyle;
543 : }
544 :
545 : /*
546 : Called by VO_PARA or other objects to get style name based on the Style object ID
547 : 1) Get style from LwpParaStyleMap based on the LwpObjectID of VO_PARASTYLE.
548 : Prerequisite: VO_PARASTYLE/VO_CHARACTERSTYLE should call AddStyle first.
549 : Return empty string if no style found.
550 : */
551 0 : IXFStyle* LwpStyleManager::GetStyle(const LwpObjectID &styleObjID)
552 : {
553 0 : LwpStyleMap::const_iterator it = m_StyleList.find(styleObjID);
554 0 : if (it != m_StyleList.end()) {
555 0 : return((*it).second);
556 : }
557 0 : return NULL;
558 : }
559 :
560 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|