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