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