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 - TOC related object
59 : */
60 : /*************************************************************************
61 : * Change History
62 : April 2005 Created
63 : April 2005 Modified
64 : April 2005 Modified - add LwpTocLevelData class
65 : ************************************************************************/
66 : #include "lwptoc.hxx"
67 : #include "lwpfoundry.hxx"
68 : #include "lwpdoc.hxx"
69 : #include "lwpframelayout.hxx"
70 : #include "lwpglobalmgr.hxx"
71 :
72 : #include "xfilter/xffont.hxx"
73 : #include "xfilter/xftextstyle.hxx"
74 : #include "xfilter/xfstylemanager.hxx"
75 : #include "xfilter/xfparagraph.hxx"
76 : #include "xfilter/xfparastyle.hxx"
77 : #include "xfilter/xfindex.hxx"
78 : #include "xfilter/xffloatframe.hxx"
79 : #include "xfilter/xfframestyle.hxx"
80 : #include "xfilter/xfframe.hxx"
81 : #include "xfilter/xftable.hxx"
82 :
83 0 : LwpTocSuperLayout::LwpTocSuperLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
84 : : LwpSuperTableLayout(objHdr, pStrm)
85 : , m_nFrom(0)
86 0 : , m_pCont(NULL)
87 : {
88 0 : }
89 :
90 0 : LwpTocSuperLayout::~LwpTocSuperLayout()
91 : {
92 0 : }
93 :
94 : /**
95 : * @short Read TOCSUPERTABLELAYOUT object
96 : * @return none
97 : */
98 0 : void LwpTocSuperLayout::Read()
99 : {
100 0 : LwpSuperTableLayout::Read();
101 0 : m_TextMarker.Read(m_pObjStrm);
102 0 : m_ParentName.Read(m_pObjStrm);
103 0 : m_DivisionName.Read(m_pObjStrm);
104 0 : m_SectionName.Read(m_pObjStrm);
105 0 : m_nFrom = m_pObjStrm->QuickReaduInt16();
106 :
107 0 : m_SearchItems.Read(m_pObjStrm);
108 :
109 : sal_uInt16 i;
110 0 : sal_uInt16 count = m_pObjStrm->QuickReaduInt16();
111 0 : for (i = 0; (i < MAX_LEVELS) && (count > 0); i++, count--)
112 0 : m_DestName[i].Read(m_pObjStrm);
113 :
114 0 : count = m_pObjStrm->QuickReaduInt16();
115 0 : for (i = 0; (i < MAX_LEVELS) && (count > 0); i++, count--)
116 0 : m_DestPGName[i].Read(m_pObjStrm);
117 :
118 0 : count = m_pObjStrm->QuickReaduInt16();
119 0 : for (i = 0; i < count; i++)
120 0 : m_nFlags[i] = m_pObjStrm->QuickReaduInt32();
121 :
122 0 : m_pObjStrm->SkipExtra();
123 0 : }
124 : /**
125 : * @short Register style of TOC
126 : * @return none
127 : */
128 0 : void LwpTocSuperLayout::RegisterStyle()
129 : {
130 0 : LwpSuperTableLayout::RegisterStyle();
131 :
132 : // Get font info of default text style and set into tab style
133 0 : XFParaStyle* pBaseStyle = static_cast<XFParaStyle*>(m_pFoundry->GetStyleManager()->GetStyle(*m_pFoundry->GetDefaultTextStyle()));
134 0 : XFTextStyle*pTextStyle = new XFTextStyle;
135 0 : pTextStyle->SetFont(pBaseStyle->GetFont()); // who delete this font?????
136 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
137 0 : m_TabStyleName = pXFStyleManager->AddStyle(pTextStyle).m_pStyle->GetStyleName();
138 :
139 0 : }
140 : /**
141 : * @short Convert TOC
142 : * @param pCont - container
143 : * @return none
144 : */
145 0 : void LwpTocSuperLayout::XFConvert(XFContentContainer* pCont)
146 : {
147 0 : XFIndex* pToc = new XFIndex();
148 :
149 0 : pToc->SetProtected(false);
150 0 : pToc->SetIndexType(enumXFIndexTOC);
151 :
152 : // add TOC template
153 0 : for (sal_uInt16 i = 1; i<= MAX_LEVELS; i++)
154 : {
155 0 : LwpTocLevelData * pLevel = GetSearchLevelPtr(i);
156 0 : XFIndexTemplate * pTemplate = new XFIndexTemplate();
157 :
158 0 : if(!pLevel)
159 : {
160 : // add an blank template so that SODC won't add default style to this level
161 0 : pToc->AddTemplate(OUString::number(i), OUString(), pTemplate);
162 0 : continue;
163 : }
164 :
165 0 : bool bInserted = false;
166 0 : do
167 : {
168 : // One level has 1 template
169 0 : if (!bInserted)
170 : {
171 0 : pTemplate->SetLevel(OUString::number(i));
172 0 : if(pLevel->GetUseLeadingText())
173 : {
174 0 : pTemplate->AddEntry(enumXFIndexTemplateChapter, pLevel->GetSearchStyle());
175 : }
176 0 : if(pLevel->GetUseText())
177 : {
178 0 : pTemplate->AddEntry(enumXFIndexTemplateText, pLevel->GetSearchStyle());
179 : }
180 0 : if(GetUsePageNumber(i))
181 : {
182 0 : sal_uInt16 nLeaderType = GetSeparatorType(i);
183 0 : if (GetRightAlignPageNumber(i))
184 : {
185 0 : char cSep = ' ';
186 0 : switch(nLeaderType)
187 : {
188 : default: // go through
189 : case NONE: // no leaders
190 0 : cSep = ' ';
191 0 : break;
192 : case LEADERDOTS:
193 0 : cSep = '.';
194 0 : break;
195 : case LEADERDASHES:
196 0 : cSep = '-';
197 0 : break;
198 : case LEADERUNDERLINE:
199 0 : cSep = '_';
200 0 : break;
201 : }
202 :
203 0 : pTemplate->AddTabEntry(enumXFTabRight, 0, cSep, 'd', m_TabStyleName);
204 : }
205 : else
206 : {
207 0 : OUString sSep;
208 0 : switch(nLeaderType)
209 : {
210 : default: // go through
211 : case NONE: // no leaders
212 0 : sSep = " ";
213 0 : break;
214 : case SEPARATORCOMMA:
215 0 : sSep = ", ";
216 0 : break;
217 : case SEPARATORDOTS:
218 0 : sSep = "...";
219 0 : break;
220 : }
221 0 : pTemplate->AddTextEntry(sSep, m_TabStyleName);
222 : }
223 : //"TOC Page Number Text Style" style always exists in Word Pro file
224 0 : pTemplate->AddEntry(enumXFIndexTemplatePage, "TOC Page Number Text Style");
225 : }
226 :
227 0 : pToc->AddTemplate(OUString::number((sal_Int32)i), m_pFoundry->FindActuralStyleName(pLevel->GetSearchStyle()), pTemplate);
228 0 : bInserted = true;
229 : }
230 :
231 : // 1 style in WordPro may be mapped to several styles in SODC
232 0 : LwpDocument * pDocument = m_pFoundry->GetDocument()->GetRootDocument();
233 0 : AddSourceStyle(pToc, pLevel, pDocument->GetFoundry());
234 :
235 : // one level may have several corresponding Styles
236 0 : pLevel = GetNextSearchLevelPtr(i, pLevel); // find next LwpTocLevelData which is same index
237 : }while (pLevel != NULL);
238 : }
239 :
240 0 : m_pCont = pCont;
241 : // add TOC content
242 0 : LwpSuperTableLayout::XFConvert(pToc);
243 :
244 : // if current TOC is located in a cell, we must add a frame between upper level container and TOC
245 0 : if ( !GetContainerLayout()->IsCell() )
246 : {
247 0 : pCont->Add(pToc);
248 : }
249 0 : }
250 :
251 : /**
252 : * @short convert frame which anchor to page
253 : * @param pCont -
254 : * @return
255 : */
256 0 : void LwpTocSuperLayout::XFConvertFrame(XFContentContainer* pCont, sal_Int32 nStart, sal_Int32 nEnd, bool bAll)
257 : {
258 0 : if(m_pFrame)
259 : {
260 0 : XFFrame* pXFFrame = NULL;
261 0 : if(nEnd < nStart)
262 : {
263 0 : pXFFrame = new XFFrame();
264 : }
265 : else
266 : {
267 0 : pXFFrame = new XFFloatFrame(nStart, nEnd, bAll);
268 : }
269 :
270 0 : m_pFrame->Parse(pXFFrame, static_cast<sal_uInt16>(nStart));
271 :
272 : //parse table, and add table to frame or TOC
273 0 : LwpTableLayout * pTableLayout = GetTableLayout();
274 0 : if (pTableLayout)
275 : {
276 0 : XFContentContainer * pTableContainer = pXFFrame;
277 : // if *this is a TOCSuperTableLayout and it's located in a cell
278 : // add the frame to upper level and add TOCSuperTableLayout into the frame
279 0 : if ( GetContainerLayout()->IsCell() )
280 : {
281 0 : pTableContainer = pCont; // TOC contain table directly
282 0 : pXFFrame->Add(pCont);
283 0 : m_pCont->Add(pXFFrame);
284 : }
285 : else
286 : {
287 : //add frame to the container
288 0 : pCont ->Add(pXFFrame);
289 : }
290 0 : pTableLayout->XFConvert(pTableContainer);
291 : }
292 : }
293 :
294 0 : }
295 :
296 : /**
297 : * @short Add source style into TOC
298 : * @param pToc - TOC pointer
299 : * @param pLevel - TOC level data
300 : * @param pFoundry - foundry pointer
301 : * @return sal_Bool
302 : */
303 0 : void LwpTocSuperLayout::AddSourceStyle(XFIndex* pToc, LwpTocLevelData * pLevel, LwpFoundry * pFoundry)
304 : {
305 0 : if (!pLevel)
306 : {
307 0 : return;
308 : }
309 :
310 0 : OUString sLwpStyleName = pLevel->GetSearchStyle();
311 :
312 0 : if (pFoundry)
313 : {
314 0 : LwpDocument * pDoc = pFoundry->GetDocument();
315 0 : if (pDoc && pDoc->IsChildDoc())
316 : {
317 0 : OUString sSodcStyleName = pFoundry->FindActuralStyleName(sLwpStyleName);
318 0 : pToc->AddTocSource(pLevel->GetLevel(), sSodcStyleName);
319 : }
320 : else
321 : {
322 0 : pDoc = pDoc->GetFirstDivision();
323 0 : while (pDoc)
324 : {
325 0 : AddSourceStyle(pToc, pLevel, pDoc->GetFoundry() );
326 0 : pDoc = pDoc->GetNextDivision();
327 : }
328 : }
329 0 : }
330 : }
331 :
332 : /**
333 : * @short Get whether page number is right alignment
334 : * @param index - TOC level
335 : * @return sal_Bool
336 : */
337 0 : bool LwpTocSuperLayout::GetRightAlignPageNumber(sal_uInt16 index)
338 : {
339 0 : if (index < MAX_LEVELS)
340 0 : return (m_nFlags[index] & TS_RIGHTALIGN) != 0;
341 0 : return false;
342 : }
343 : /**
344 : * @short Get whether page number is used in TOC entries
345 : * @param index - TOC level
346 : * @return sal_Bool
347 : */
348 0 : bool LwpTocSuperLayout::GetUsePageNumber(sal_uInt16 index)
349 : {
350 0 : if (index < MAX_LEVELS)
351 0 : return (m_nFlags[index] & TS_PAGENUMBER) != 0;
352 0 : return false;
353 : }
354 : /**
355 : * @short Get what is used for separater
356 : * @param index - TOC level
357 : * @return sal_uInt16 - separator type
358 : */
359 0 : sal_uInt16 LwpTocSuperLayout::GetSeparatorType(sal_uInt16 index)
360 : {
361 0 : if (index >= MAX_LEVELS)
362 0 : return NONE;
363 :
364 0 : sal_uInt16 Flag = (sal_uInt16)m_nFlags[index];
365 :
366 0 : if (Flag & TS_LEADERDOTS)
367 0 : return LEADERDOTS;
368 0 : else if (Flag & TS_LEADERDASHES)
369 0 : return LEADERDASHES;
370 0 : else if (Flag & TS_LEADERUNDERLINE)
371 0 : return LEADERUNDERLINE;
372 0 : else if (Flag & TS_SEPARATORCOMMA)
373 0 : return SEPARATORCOMMA;
374 0 : else if (Flag & TS_SEPARATORDOTS)
375 0 : return SEPARATORDOTS;
376 : else
377 0 : return NONE;
378 : }
379 :
380 : /**
381 : * @short Get TOCLEVELDATA obj
382 : * @param index - TOC level
383 : * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
384 : */
385 0 : LwpTocLevelData * LwpTocSuperLayout::GetSearchLevelPtr(sal_uInt16 index)
386 : {
387 0 : LwpObjectID& rID = m_SearchItems.GetHead();
388 0 : LwpTocLevelData * pObj = dynamic_cast<LwpTocLevelData *>(rID.obj().get());
389 :
390 0 : while(pObj)
391 : {
392 0 : if(pObj->GetLevel()== index)
393 : {
394 0 : return pObj;
395 : }
396 :
397 0 : rID = pObj->GetNext();
398 0 : pObj = dynamic_cast<LwpTocLevelData *>(rID.obj().get());
399 : }
400 :
401 0 : return NULL;
402 : }
403 : /**
404 : * @short Get next TOCLEVELDATA obj from current position
405 : * @param index - TOC level
406 : * @param pCurData - current LwpTocLevelData
407 : * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
408 : */
409 0 : LwpTocLevelData * LwpTocSuperLayout::GetNextSearchLevelPtr(sal_uInt16 index, LwpTocLevelData * pCurData)
410 : {
411 0 : LwpObjectID& rID = pCurData->GetNext();
412 0 : LwpTocLevelData * pObj = dynamic_cast<LwpTocLevelData *>(rID.obj().get());
413 :
414 0 : while(pObj)
415 : {
416 0 : if(pObj->GetLevel()== index)
417 : {
418 0 : return pObj;
419 : }
420 :
421 0 : rID = pObj->GetNext();
422 0 : pObj = dynamic_cast<LwpTocLevelData *>(rID.obj().get());
423 : }
424 :
425 0 : return NULL;
426 : }
427 :
428 0 : LwpTocLevelData::LwpTocLevelData(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpDLVList(objHdr, pStrm)
429 : {
430 0 : m_nFlags = 0;
431 0 : m_nLevel = 0;
432 0 : }
433 0 : LwpTocLevelData::~LwpTocLevelData()
434 : {
435 0 : }
436 : /**
437 : * @short Register style
438 : * @param
439 : * @return
440 : */
441 0 : void LwpTocLevelData::RegisterStyle()
442 : {
443 0 : }
444 : /**
445 : * @short Convert
446 : * @param pCont - container
447 : * @return none
448 : */
449 0 : void LwpTocLevelData::XFConvert(XFContentContainer* /*pCont*/)
450 : {
451 0 : }
452 : /**
453 : * @short Read TOCLEVELDATA obj
454 : * @param
455 : * @return
456 : */
457 0 : void LwpTocLevelData::Read()
458 : {
459 0 : LwpDLVList::Read();
460 0 : m_nFlags = m_pObjStrm->QuickReaduInt16();
461 0 : m_nLevel = m_pObjStrm->QuickReaduInt16();
462 0 : m_SearchName.Read(m_pObjStrm);
463 :
464 0 : m_pObjStrm->SkipExtra();
465 0 : }
466 :
467 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|