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 : Mar 2005 Created
63 : ************************************************************************/
64 : #include "lwpfoundry.hxx"
65 : #include "lwpfilehdr.hxx"
66 : #include "lwpstory.hxx"
67 : #include "lwpmarker.hxx"
68 : #include "lwpproplist.hxx"
69 : #include "lwpglobalmgr.hxx"
70 : #include "xfilter/xfplaceholder.hxx"
71 : #include "xfilter/xfinputlist.hxx"
72 :
73 4 : LwpMarker::LwpMarker(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
74 : : LwpDLNFPVList(objHdr,pStrm)
75 : , m_nFlag(0)
76 : , m_nPageNumber(0)
77 4 : , m_nNeedUpdate(0)
78 : {
79 4 : }
80 :
81 4 : void LwpMarker::Read()
82 : {
83 4 : LwpDLNFPVList::Read();
84 4 : m_objContent.ReadIndexed(m_pObjStrm);
85 4 : m_objLayout.ReadIndexed(m_pObjStrm);
86 4 : m_objMarkerList.ReadIndexed(m_pObjStrm);
87 4 : m_nNeedUpdate = m_pObjStrm->QuickReaduInt16();
88 4 : m_nFlag = m_pObjStrm->QuickReaduInt16();
89 4 : m_nPageNumber = m_pObjStrm->QuickReaduInt16();
90 :
91 4 : m_pObjStrm->SkipExtra();
92 4 : }
93 :
94 0 : OUString LwpMarker::GetNamedProperty(const OUString& name)
95 : {
96 0 : LwpPropList* pProp = GetPropList();
97 0 : if (pProp)
98 0 : return pProp->GetNamedProperty(name);
99 : else
100 0 : return OUString("");
101 : }
102 :
103 4 : LwpStoryMarker::LwpStoryMarker(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
104 : : LwpMarker(objHdr,pStrm)
105 4 : , m_nFlag(0)
106 : {
107 4 : }
108 :
109 4 : void LwpStoryMarker::Read()
110 : {
111 4 : LwpMarker::Read();
112 4 : m_nFlag = m_pObjStrm->QuickReaduInt16();
113 4 : m_Range.Read(m_pObjStrm);
114 4 : m_pObjStrm->SkipExtra();
115 4 : }
116 :
117 4 : void LwpFribRange::Read(LwpObjectStream* pObjStrm)
118 : {
119 4 : m_StartPara.ReadIndexed(pObjStrm);
120 4 : m_EndPara.ReadIndexed(pObjStrm);
121 4 : }
122 :
123 0 : LwpCHBlkMarker::LwpCHBlkMarker(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
124 : : LwpStoryMarker(objHdr, pStrm)
125 : , m_nTab(0)
126 : , m_nFlag(0)
127 0 : , m_nAction(0)
128 : {
129 0 : }
130 :
131 0 : void LwpCHBlkMarker::Read()
132 : {
133 0 : LwpStoryMarker::Read();
134 0 : m_objPromptStory.ReadIndexed(m_pObjStrm);
135 0 : m_Help.Read(m_pObjStrm);
136 0 : m_nAction = m_pObjStrm->QuickReaduInt16();
137 0 : m_nTab = m_pObjStrm->QuickReaduInt32();
138 0 : m_nFlag = m_pObjStrm->QuickReaduInt16();
139 0 : if(m_pObjStrm->CheckExtra())
140 : {
141 0 : m_Mirror.Read(m_pObjStrm);
142 0 : m_pObjStrm->SkipExtra();
143 : }
144 0 : }
145 :
146 0 : OUString LwpCHBlkMarker::GetPromptText()
147 : {
148 0 : LwpStory* pStory = NULL;
149 0 : if (m_objPromptStory.obj().is())
150 0 : pStory = dynamic_cast<LwpStory*>(m_objPromptStory.obj().get());
151 0 : if (pStory)
152 0 : return pStory->GetContentText();
153 0 : return OUString("");
154 : }
155 :
156 0 : void LwpCHBlkMarker::ConvertCHBlock(XFContentContainer* pXFPara, sal_uInt8 nType)
157 : {
158 0 : sal_uInt16 nAction = GetAction();
159 :
160 0 : switch(nAction)
161 : {
162 : case CLICKHERE_CHBEHAVIORTEXT:
163 : case CLICKHERE_CHBEHAVIORTABLE:
164 : case CLICKHERE_CHBEHAVIORPICTURE:
165 : case CLICKHERE_CHBEHAVIOROLEOBJECT:
166 0 : ProcessPlaceHolder(pXFPara,nAction,nType);
167 0 : break;
168 : case CLICKHERE_CHBEHAVIORCHART:
169 : case CLICKHERE_CHBEHAVIORDRAWING:
170 : case CLICKHERE_CHBEHAVIORGLOSSARY:
171 : case CLICKHERE_CHBEHAVIOREQUATION:
172 : case CLICKHERE_CHBEHAVIORSYMBOL:
173 : case CLICKHERE_CHBEHAVIORPAGENUM:
174 : case CLICKHERE_CHBEHAVIORDOCFIELD:
175 : case CLICKHERE_CHBEHAVIORDATETIME:
176 0 : ProcessOtherCHB(pXFPara,nType);
177 0 : break;
178 : case CLICKHERE_CHBEHAVIORSTRINGLIST:
179 0 : ProcessKeylist(pXFPara,nType);
180 0 : break;
181 : default:
182 0 : break;
183 : }
184 0 : }
185 :
186 0 : void LwpCHBlkMarker::ProcessPlaceHolder(XFContentContainer* pXFPara,sal_uInt16 nAction,
187 : sal_uInt8 nType)
188 : {
189 0 : bool bFillFlag = IsHasFilled();
190 0 : bool bHelpFlag = IsBubbleHelp();
191 :
192 0 : if ( bFillFlag )
193 0 : return;
194 0 : if (nType == MARKER_START)
195 : {
196 0 : XFHolderStart* pHolder= new XFHolderStart;
197 0 : switch(nAction)
198 : {
199 : case CLICKHERE_CHBEHAVIORTEXT:
200 0 : pHolder->SetType("text");
201 0 : break;
202 : case CLICKHERE_CHBEHAVIORTABLE:
203 0 : pHolder->SetType("table");
204 0 : break;
205 : case CLICKHERE_CHBEHAVIORPICTURE:
206 0 : pHolder->SetType("image");
207 0 : break;
208 : case CLICKHERE_CHBEHAVIOROLEOBJECT:
209 0 : pHolder->SetType("object");
210 0 : break;
211 : default:
212 0 : break;
213 : }
214 :
215 0 : if (bHelpFlag)
216 0 : pHolder->SetDesc(m_Help.str());
217 0 : pHolder->SetPrompt(GetPromptText());
218 0 : pXFPara->Add(pHolder);
219 : }
220 0 : else if (nType == MARKER_END)
221 : {
222 0 : XFHolderEnd* pHolder = new XFHolderEnd;
223 0 : pXFPara->Add(pHolder);
224 : }
225 : }
226 :
227 0 : void LwpCHBlkMarker::ProcessOtherCHB(XFContentContainer* pXFPara,sal_uInt8 nType)
228 : {
229 0 : bool bFillFlag = IsHasFilled();
230 0 : bool bHelpFlag = IsBubbleHelp();
231 :
232 0 : if ( bFillFlag )
233 0 : return;
234 0 : if (nType == MARKER_START)
235 : {
236 0 : XFHolderStart* pHolder= new XFHolderStart;
237 0 : pHolder->SetType("text");
238 0 : if (bHelpFlag)
239 0 : pHolder->SetDesc(m_Help.str());
240 0 : pHolder->SetPrompt(GetPromptText());
241 0 : pXFPara->Add(pHolder);
242 : }
243 0 : else if (nType == MARKER_END)
244 : {
245 0 : XFHolderEnd* pHolder = new XFHolderEnd;
246 0 : pXFPara->Add(pHolder);
247 : }
248 :
249 : }
250 :
251 : //note: there will be a blank to mark the list
252 : //all input content of key list processed as normal text
253 0 : void LwpCHBlkMarker::ProcessKeylist(XFContentContainer* pXFPara,sal_uInt8 nType)
254 : {
255 0 : bool bFillFlag = IsHasFilled();
256 :
257 0 : if ( bFillFlag )
258 : {
259 0 : if (nType == MARKER_START)
260 : {
261 0 : EnumAllKeywords();//traverse the proplist to find all keywords
262 0 : XFInputList* pList = new XFInputList;
263 0 : pList->SetName(LwpDLNFPVList::m_Name.str());
264 0 : pList->SetLabels(m_Keylist);
265 0 : pXFPara->Add(pList);
266 : }
267 : else if (nType == MARKER_END)//skip
268 : {
269 : }
270 : }
271 : else
272 : {
273 0 : if (nType == MARKER_START)
274 : {
275 0 : EnumAllKeywords();
276 0 : XFInputList* pList = new XFInputList;
277 0 : pList->SetName(LwpDLNFPVList::m_Name.str());
278 0 : pList->SetLabels(m_Keylist);
279 0 : pXFPara->Add(pList);
280 :
281 0 : XFHolderStart* pHolder= new XFHolderStart;
282 0 : pHolder->SetType("text");
283 0 : pHolder->SetPrompt(GetPromptText());
284 0 : pXFPara->Add(pHolder);
285 : }
286 0 : else if (nType == MARKER_END)
287 : {
288 0 : XFHolderEnd* pHolder = new XFHolderEnd;
289 0 : pXFPara->Add(pHolder);
290 : }
291 : }
292 0 : }
293 :
294 0 : bool LwpCHBlkMarker::IsHasFilled()
295 : {
296 0 : if (CHB_PROMPT & m_nFlag)
297 0 : return false;
298 0 : return true;
299 : }
300 :
301 0 : bool LwpCHBlkMarker::IsBubbleHelp()
302 : {
303 0 : return (CHB_HELP & m_nFlag) != 0;
304 : }
305 :
306 0 : void LwpCHBlkMarker::EnumAllKeywords()
307 : {
308 0 : OUString name1("");
309 0 : OUString value1("");
310 0 : OUString name2("start");
311 0 : LwpPropList* pProp = GetPropList();
312 0 : if (!pProp)
313 0 : return;
314 0 : while(!name2.isEmpty())
315 : {
316 0 : name2 = pProp->EnumNamedProperty(name1,value1);
317 0 : if ( name1.match("LIST",0) )
318 : {
319 0 : m_Keylist.push_back(value1);
320 : }
321 0 : name1 = name2;
322 0 : }
323 : }
324 :
325 0 : LwpBookMark::LwpBookMark(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
326 : : LwpDLNFVList(objHdr,pStrm)
327 0 : , m_nFlag(0)
328 : {
329 0 : }
330 :
331 0 : void LwpBookMark::Read()
332 : {
333 0 : LwpDLNFVList::Read();
334 0 : m_objMarker.ReadIndexed(m_pObjStrm);
335 0 : if (LwpFileHeader::m_nFileRevision < 0x0008)
336 : {
337 0 : if (m_pObjStrm->QuickReadBool())
338 0 : m_nFlag |= BKMK_NOTESFX;
339 : }
340 : else
341 0 : m_nFlag = m_pObjStrm->QuickReaduInt16();
342 0 : m_pObjStrm->SkipExtra();
343 0 : }
344 :
345 0 : bool LwpBookMark::IsRightMarker(LwpObjectID objMarker)
346 : {
347 0 : if (objMarker == m_objMarker)
348 0 : return true;
349 0 : return false;
350 : }
351 :
352 0 : OUString LwpBookMark::GetName()
353 : {
354 0 : return LwpDLNFVList::GetName().str();
355 : }
356 :
357 4 : LwpFieldMark::LwpFieldMark(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
358 : : LwpStoryMarker(objHdr,pStrm)
359 : , m_nFlag(0)
360 : , m_nFieldType(0)
361 : , m_bHasStyle(false)
362 : , m_bHasStart(false)
363 : , m_pFrib(NULL)
364 4 : , m_bRevisionFlag(false)
365 : {
366 4 : }
367 :
368 4 : void LwpFieldMark::Read()
369 : {
370 4 : LwpStoryMarker::Read();
371 4 : m_Formula.Read(m_pObjStrm);
372 4 : m_objFormulaStory.ReadIndexed(m_pObjStrm);
373 4 : if (LwpFileHeader::m_nFileRevision < 0x000B)
374 4 : return;
375 4 : m_objResultContent.ReadIndexed(m_pObjStrm);
376 4 : m_nFlag = m_pObjStrm->QuickReaduInt16();
377 4 : m_nFieldType = m_pObjStrm->QuickReaduInt16();
378 4 : m_pObjStrm->SkipExtra();
379 : }
380 :
381 0 : void LwpFieldMark::ParseIndex(OUString& sKey1,OUString& sKey2)
382 : {
383 0 : OUString sFormula = m_Formula.str();
384 : sal_Int32 index[4];
385 0 : sal_Unicode ch(0x0022);//"
386 0 : index[0] = sFormula.indexOf(ch,0);
387 0 : index[1] = sFormula.indexOf(ch,index[0]+1);
388 :
389 0 : index[2] = sFormula.indexOf(ch,index[1]+1);
390 0 : index[3] = sFormula.indexOf(ch,index[2]+1);
391 0 : if (index[0]>=0 && index[1]>=0)
392 0 : sKey1 = sFormula.copy(index[0]+1,index[1]-index[0]-1);
393 : else
394 0 : sKey1 = "";
395 0 : if (index[2]>=0 && index[3]>=0)
396 0 : sKey2 = sFormula.copy(index[2]+1,index[3]-index[2]-1);
397 : else
398 0 : sKey2 = "";
399 0 : }
400 :
401 0 : void LwpFieldMark::ParseTOC(OUString& sLevel,OUString& sText)
402 : {
403 0 : OUString sFormula = m_Formula.str();
404 : sal_Int32 index[4];
405 0 : sal_Unicode ch1(0x0020);//space
406 0 : sal_Unicode ch2(0x0022);//"
407 :
408 0 : index[0] = sFormula.indexOf(ch1,0);
409 0 : index[1] = sFormula.indexOf(ch1,index[0]+1);
410 :
411 0 : index[2] = sFormula.indexOf(ch2,index[1]+1);
412 0 : index[3] = sFormula.indexOf(ch2,index[2]+1);
413 0 : if (index[0]>=0 && index[1]>=0)
414 0 : sLevel = sFormula.copy(index[0]+1,index[1]-index[0]-1);
415 : else
416 0 : sLevel = "";
417 0 : if (index[2]>=0 && index[3]>=0)
418 0 : sText = sFormula.copy(index[2]+1,index[3]-index[2]-1);
419 : else
420 0 : sText = "";
421 0 : }
422 :
423 8 : bool LwpFieldMark::IsFormulaInsert()
424 : {
425 8 : if (m_nFlag & FF_FORMULAINSERTED)
426 0 : return true;
427 8 : return false;
428 : }
429 :
430 12 : bool LwpFieldMark::IsDateTimeField(sal_uInt8& type,OUString& formula)
431 : {
432 12 : OUString sFormula = m_Formula.str();
433 : sal_Int32 index;
434 12 : sal_Unicode ch1(0x0020);//space
435 24 : OUString tag;
436 :
437 12 : index = sFormula.indexOf(ch1,0);
438 12 : if (index < 0)
439 : {
440 0 : if (sFormula == "TotalEditingTime")
441 : {
442 0 : type = DATETIME_TOTALTIME;
443 0 : return true;
444 : }
445 0 : return false;
446 : }
447 :
448 12 : tag = sFormula.copy(0,index);
449 12 : if (tag == "Now()")
450 : {
451 12 : type = DATETIME_NOW;
452 12 : formula = sFormula.copy(index+1,sFormula.getLength()-index-1);
453 12 : return true;
454 : }
455 0 : else if (tag == "CreateDate")
456 : {
457 0 : type = DATETIME_CREATE;
458 0 : formula = sFormula.copy(index+1,sFormula.getLength()-index-1);
459 0 : return true;
460 : }
461 0 : else if (tag == "EditDate")
462 : {
463 0 : type = DATETIME_LASTEDIT;
464 0 : formula = sFormula.copy(index+1,sFormula.getLength()-index-1);
465 0 : return true;
466 : }
467 0 : else if (tag == "YesterdaysDate" || tag == "TomorrowsDate"
468 0 : || tag == "TodaysDate")
469 : {
470 0 : type = DATETIME_SKIP;
471 0 : return true;
472 : }
473 : else
474 12 : return false;
475 : }
476 :
477 0 : bool LwpFieldMark::IsCrossRefField(sal_uInt8& nType, OUString& sMarkName)
478 : {
479 0 : OUString sFormula = m_Formula.str();
480 : sal_Int32 index;
481 0 : sal_Unicode ch1(0x0020);//space
482 0 : OUString tag;
483 :
484 0 : index = sFormula.indexOf(ch1,0);
485 0 : if (index < 0)
486 : {
487 0 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
488 0 : LwpBookmarkMgr* pMarkMgr = pGlobal->GetLwpBookmarkMgr();
489 0 : if (pMarkMgr->FindBookmark(sFormula))
490 : {
491 0 : sMarkName = sFormula;
492 0 : nType = CROSSREF_TEXT;
493 0 : return true;
494 : }
495 : else
496 0 : return false;
497 : }
498 :
499 0 : tag = sFormula.copy(0,index);
500 0 : if (tag == "PageRef")
501 : {
502 0 : sMarkName = sFormula.copy(index+1,sFormula.getLength()-index-1);
503 0 : nType = CROSSREF_PAGE;
504 0 : return true;
505 : }
506 0 : else if (tag == "ParaRef")
507 : {
508 0 : sMarkName = sFormula.copy(index+1,sFormula.getLength()-index-1);
509 0 : nType = CROSSREF_PARANUMBER;
510 0 : return true;
511 : }
512 : else
513 0 : return false;
514 : }
515 :
516 0 : bool LwpFieldMark::IsDocPowerField(sal_uInt8& nType,OUString& sFormula)
517 : {
518 0 : sFormula = m_Formula.str();
519 :
520 0 : if (sFormula == "Description")
521 : {
522 0 : nType = DOC_DESCRIPTION;
523 0 : return true;
524 : }
525 0 : else if (sFormula == "NumPages")
526 : {
527 0 : nType = DOC_NUMPAGES;
528 0 : return true;
529 : }
530 0 : else if (sFormula == "NumChars")
531 : {
532 0 : nType = DOC_NUMCHARS;
533 0 : return true;
534 : }
535 0 : else if (sFormula == "NumWords")
536 : {
537 0 : nType = DOC_NUMWORDS;
538 0 : return true;
539 : }
540 : else
541 : {
542 0 : return false;
543 : }
544 : }
545 :
546 0 : LwpRubyMarker::LwpRubyMarker(LwpObjectHeader &objHdr, LwpSvStream *pStrm):LwpStoryMarker(objHdr,pStrm)
547 : {
548 0 : }
549 :
550 0 : void LwpRubyMarker::Read()
551 : {
552 0 : LwpStoryMarker::Read();
553 0 : m_objLayout.ReadIndexed(m_pObjStrm);
554 0 : m_pObjStrm->SkipExtra();
555 0 : }
556 :
557 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|