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 0 : LwpMarker::LwpMarker(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
74 : : LwpDLNFPVList(objHdr,pStrm)
75 : , m_nFlag(0)
76 : , m_nPageNumber(0)
77 0 : , m_nNeedUpdate(0)
78 : {
79 0 : }
80 :
81 0 : void LwpMarker::Read()
82 : {
83 0 : LwpDLNFPVList::Read();
84 0 : m_objContent.ReadIndexed(m_pObjStrm);
85 0 : m_objLayout.ReadIndexed(m_pObjStrm);
86 0 : m_objMarkerList.ReadIndexed(m_pObjStrm);
87 0 : m_nNeedUpdate = m_pObjStrm->QuickReaduInt16();
88 0 : m_nFlag = m_pObjStrm->QuickReaduInt16();
89 0 : m_nPageNumber = m_pObjStrm->QuickReaduInt16();
90 :
91 0 : m_pObjStrm->SkipExtra();
92 0 : }
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 0 : LwpStoryMarker::LwpStoryMarker(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
104 : : LwpMarker(objHdr,pStrm)
105 0 : , m_nFlag(0)
106 : {
107 0 : }
108 :
109 0 : void LwpStoryMarker::Read()
110 : {
111 0 : LwpMarker::Read();
112 0 : m_nFlag = m_pObjStrm->QuickReaduInt16();
113 0 : m_Range.Read(m_pObjStrm);
114 0 : m_pObjStrm->SkipExtra();
115 0 : }
116 :
117 0 : void LwpFribRange::Read(LwpObjectStream* pObjStrm)
118 : {
119 0 : m_StartPara.ReadIndexed(pObjStrm);
120 0 : m_EndPara.ReadIndexed(pObjStrm);
121 0 : }
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())
150 0 : pStory = dynamic_cast<LwpStory*>(m_objPromptStory.obj());
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 : sal_Bool bFillFlag = IsHasFilled();
190 0 : sal_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 : sal_Bool bFillFlag = IsHasFilled();
230 0 : sal_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 : sal_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 : sal_Bool LwpCHBlkMarker::IsHasFilled()
295 : {
296 0 : if (CHB_PROMPT & m_nFlag)
297 0 : return sal_False;
298 0 : return sal_True;
299 : }
300 :
301 0 : sal_Bool LwpCHBlkMarker::IsBubbleHelp()
302 : {
303 0 : return (CHB_HELP & m_nFlag);
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 : sal_Bool LwpBookMark::IsRightMarker(LwpObjectID objMarker)
346 : {
347 0 : if (objMarker == m_objMarker)
348 0 : return sal_True;
349 0 : return sal_False;
350 : }
351 :
352 0 : OUString LwpBookMark::GetName()
353 : {
354 0 : if (LwpDLNFVList::GetName())
355 0 : return LwpDLNFVList::GetName()->str();
356 : else
357 0 : return OUString("");
358 : }
359 :
360 0 : LwpFieldMark::LwpFieldMark(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
361 : : LwpStoryMarker(objHdr,pStrm)
362 : , m_nFlag(0)
363 : , m_nFieldType(0)
364 : , m_bHasStyle(sal_False)
365 : , m_bHasStart(sal_False)
366 : , m_pFrib(NULL)
367 0 : , m_bRevisionFlag(sal_False)
368 : {
369 0 : }
370 :
371 0 : void LwpFieldMark::Read()
372 : {
373 0 : LwpStoryMarker::Read();
374 0 : m_Formula.Read(m_pObjStrm);
375 0 : m_objFormulaStory.ReadIndexed(m_pObjStrm);
376 0 : if (LwpFileHeader::m_nFileRevision < 0x000B)
377 0 : return;
378 0 : m_objResultContent.ReadIndexed(m_pObjStrm);
379 0 : m_nFlag = m_pObjStrm->QuickReaduInt16();
380 0 : m_nFieldType = m_pObjStrm->QuickReaduInt16();
381 0 : m_pObjStrm->SkipExtra();
382 : }
383 :
384 0 : void LwpFieldMark::ParseIndex(OUString& sKey1,OUString& sKey2)
385 : {
386 0 : OUString sFormula = m_Formula.str();
387 : sal_Int32 index[4];
388 0 : sal_Unicode ch(0x0022);//"
389 0 : index[0] = sFormula.indexOf(ch,0);
390 0 : index[1] = sFormula.indexOf(ch,index[0]+1);
391 :
392 0 : index[2] = sFormula.indexOf(ch,index[1]+1);
393 0 : index[3] = sFormula.indexOf(ch,index[2]+1);
394 0 : if (index[0]>=0 && index[1]>=0)
395 0 : sKey1 = sFormula.copy(index[0]+1,index[1]-index[0]-1);
396 : else
397 0 : sKey1 = "";
398 0 : if (index[2]>=0 && index[3]>=0)
399 0 : sKey2 = sFormula.copy(index[2]+1,index[3]-index[2]-1);
400 : else
401 0 : sKey2 = "";
402 0 : }
403 :
404 0 : void LwpFieldMark::ParseTOC(OUString& sLevel,OUString& sText)
405 : {
406 0 : OUString sFormula = m_Formula.str();
407 : sal_Int32 index[4];
408 0 : sal_Unicode ch1(0x0020);//space
409 0 : sal_Unicode ch2(0x0022);//"
410 :
411 0 : index[0] = sFormula.indexOf(ch1,0);
412 0 : index[1] = sFormula.indexOf(ch1,index[0]+1);
413 :
414 0 : index[2] = sFormula.indexOf(ch2,index[1]+1);
415 0 : index[3] = sFormula.indexOf(ch2,index[2]+1);
416 0 : if (index[0]>=0 && index[1]>=0)
417 0 : sLevel = sFormula.copy(index[0]+1,index[1]-index[0]-1);
418 : else
419 0 : sLevel = "";
420 0 : if (index[2]>=0 && index[3]>=0)
421 0 : sText = sFormula.copy(index[2]+1,index[3]-index[2]-1);
422 : else
423 0 : sText = "";
424 0 : }
425 :
426 0 : sal_Bool LwpFieldMark::IsFormulaInsert()
427 : {
428 0 : if (m_nFlag & FF_FORMULAINSERTED)
429 0 : return sal_True;
430 0 : return sal_False;
431 : }
432 :
433 0 : sal_Bool LwpFieldMark::IsDateTimeField(sal_uInt8& type,OUString& formula)
434 : {
435 0 : OUString sFormula = m_Formula.str();
436 : sal_Int32 index;
437 0 : sal_Unicode ch1(0x0020);//space
438 0 : OUString tag;
439 :
440 0 : index = sFormula.indexOf(ch1,0);
441 0 : if (index < 0)
442 : {
443 0 : if (sFormula == "TotalEditingTime")
444 : {
445 0 : type = DATETIME_TOTALTIME;
446 0 : return sal_True;
447 : }
448 0 : return sal_False;
449 : }
450 :
451 0 : tag = sFormula.copy(0,index);
452 0 : if (tag == "Now()")
453 : {
454 0 : type = DATETIME_NOW;
455 0 : formula = sFormula.copy(index+1,sFormula.getLength()-index-1);
456 0 : return sal_True;
457 : }
458 0 : else if (tag == "CreateDate")
459 : {
460 0 : type = DATETIME_CREATE;
461 0 : formula = sFormula.copy(index+1,sFormula.getLength()-index-1);
462 0 : return sal_True;
463 : }
464 0 : else if (tag == "EditDate")
465 : {
466 0 : type = DATETIME_LASTEDIT;
467 0 : formula = sFormula.copy(index+1,sFormula.getLength()-index-1);
468 0 : return sal_True;
469 : }
470 0 : else if (tag == "YesterdaysDate" || tag == "TomorrowsDate"
471 0 : || tag == "TodaysDate")
472 : {
473 0 : type = DATETIME_SKIP;
474 0 : return sal_True;
475 : }
476 : else
477 0 : return sal_False;
478 : }
479 :
480 0 : sal_Bool LwpFieldMark::IsCrossRefField(sal_uInt8& nType, OUString& sMarkName)
481 : {
482 0 : OUString sFormula = m_Formula.str();
483 : sal_Int32 index;
484 0 : sal_Unicode ch1(0x0020);//space
485 0 : OUString tag;
486 :
487 0 : index = sFormula.indexOf(ch1,0);
488 0 : if (index < 0)
489 : {
490 0 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
491 0 : LwpBookmarkMgr* pMarkMgr = pGlobal->GetLwpBookmarkMgr();
492 0 : if (pMarkMgr->FindBookmark(sFormula))
493 : {
494 0 : sMarkName = sFormula;
495 0 : nType = CROSSREF_TEXT;
496 0 : return sal_True;
497 : }
498 : else
499 0 : return sal_False;
500 : }
501 :
502 0 : tag = sFormula.copy(0,index);
503 0 : if (tag == "PageRef")
504 : {
505 0 : sMarkName = sFormula.copy(index+1,sFormula.getLength()-index-1);
506 0 : nType = CROSSREF_PAGE;
507 0 : return sal_True;
508 : }
509 0 : else if (tag == "ParaRef")
510 : {
511 0 : sMarkName = sFormula.copy(index+1,sFormula.getLength()-index-1);
512 0 : nType = CROSSREF_PARANUMBER;
513 0 : return sal_True;
514 : }
515 : else
516 0 : return sal_False;
517 : }
518 :
519 0 : sal_Bool LwpFieldMark::IsDocPowerField(sal_uInt8& nType,OUString& sFormula)
520 : {
521 0 : sFormula = m_Formula.str();
522 :
523 0 : if (sFormula == "Description")
524 : {
525 0 : nType = DOC_DESCRIPTION;
526 0 : return sal_True;
527 : }
528 0 : else if (sFormula == "NumPages")
529 : {
530 0 : nType = DOC_NUMPAGES;
531 0 : return sal_True;
532 : }
533 0 : else if (sFormula == "NumChars")
534 : {
535 0 : nType = DOC_NUMCHARS;
536 0 : return sal_True;
537 : }
538 0 : else if (sFormula == "NumWords")
539 : {
540 0 : nType = DOC_NUMWORDS;
541 0 : return sal_True;
542 : }
543 : else
544 : {
545 0 : return sal_False;
546 : }
547 : }
548 :
549 0 : LwpRubyMarker::LwpRubyMarker(LwpObjectHeader &objHdr, LwpSvStream *pStrm):LwpStoryMarker(objHdr,pStrm)
550 : {
551 0 : }
552 :
553 0 : void LwpRubyMarker::Read()
554 : {
555 0 : LwpStoryMarker::Read();
556 0 : m_objLayout.ReadIndexed(m_pObjStrm);
557 0 : m_pObjStrm->SkipExtra();
558 0 : }
559 :
560 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|