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