merge the formfield patch from ooo-build
[ooovba.git] / lotuswordpro / source / filter / lwpfribtext.cxx
blob0dcf67b6ff25f22528126c54c28e02b401e5cd94
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /*************************************************************************
56 * @file
57 * For LWP filter architecture prototype
58 ************************************************************************/
59 /*************************************************************************
60 * Change History
61 Jan 2005 Created
62 ************************************************************************/
63 #include "lwpglobalmgr.hxx"
64 #include "lwpfribtext.hxx"
65 #include "lwpcharsetmgr.hxx"
66 #include "lwphyperlinkmgr.hxx"
67 #include "lwptools.hxx"
68 #include "xfilter/xfstylemanager.hxx"
69 #include "xfilter/xftextspan.hxx"
70 #include "xfilter/xfbookmark.hxx"
71 #include "xfilter/xfentry.hxx"
72 #include "xfilter/xftextcontent.hxx"
73 #include "xfilter/xfcrossref.hxx"
74 #include "xfilter/xfpagenumber.hxx"
75 #include "xfilter/xfdocfield.hxx"
76 #include "xfilter/xfdatestyle.hxx"
77 #include "xfilter/xftimestyle.hxx"
78 #include "xfilter/xfdate.hxx"
79 #include "xfilter/xfannotation.hxx"
81 LwpFribText::LwpFribText( LwpPara *pPara, sal_Bool bNoUnicode )
82 : LwpFrib(pPara), m_bNoUnicode(bNoUnicode)
83 {};
85 void LwpFribText::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
87 if( len>=1 )
89 rtl_TextEncoding rEncode;
90 if(m_bNoUnicode)
92 rEncode = RTL_TEXTENCODING_ISO_8859_1;
94 else
96 if (m_pModifiers && m_pModifiers->CodePage)
97 rEncode = LwpCharSetMgr::GetInstance()->
98 GetTextCharEncoding(m_pModifiers->CodePage);
99 else
100 rEncode = LwpCharSetMgr::GetInstance()->GetTextCharEncoding();
102 LwpTools::QuickReadUnicode(pObjStrm, m_Content, len, rEncode);
106 void LwpFribText::XFConvert(XFContentContainer* pXFPara,LwpStory* pStory)
108 if (!pStory)
109 return;
110 LwpHyperlinkMgr* pHyperlink = pStory->GetHyperlinkMgr();
111 if (pHyperlink->GetHyperlinkFlag())
112 LwpFrib::ConvertHyperLink(pXFPara,pHyperlink,GetText());
113 else
114 LwpFrib::ConvertChars(pXFPara,GetText());
118 * @short: Reading mothed of paranumber frib.
119 * @param: pObjStrm wordpro object stream.
120 * @param: len length of the frib
122 void LwpFribParaNumber::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
124 pObjStrm->QuickRead(&m_nStyleID, sizeof(m_nStyleID));
125 pObjStrm->QuickRead(&m_nNumberChar, sizeof(m_nNumberChar));
126 pObjStrm->QuickRead(&m_nLevel, sizeof(m_nLevel));
127 pObjStrm->QuickRead(&m_nStart, sizeof(m_nStart));
131 * @short: default constructor of LwpFribDocVar
133 LwpFribDocVar::LwpFribDocVar(LwpPara* pPara)
134 : LwpFrib(pPara), m_nType(0), m_pName(new LwpAtomHolder)
138 * @short: destructor of LwpFribDocVar
140 LwpFribDocVar::~LwpFribDocVar()
142 if (m_pName)
144 delete m_pName;
145 m_pName = NULL;
149 * @short: Reading mothed of document variable frib.
150 * @param: pObjStrm wordpro object stream.
151 * @param: len length of the frib
153 void LwpFribDocVar::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
155 pObjStrm->QuickRead(&m_nType, sizeof(m_nType));
156 m_pName->Read(pObjStrm);
160 * @short: register style for doc field (text style,date style)
161 * @param:
162 * @param:
164 void LwpFribDocVar::RegisterStyle(LwpFoundry* pFoundry)
166 LwpFrib::RegisterStyle(pFoundry);
168 switch(m_nType)
170 case DATECREATED:
171 case DATELASTREVISION:
173 // m_TimeStyle = LwpTools::RegisterDefaultTimeStyle();
174 RegisterDefaultTimeStyle();
176 break;
177 case TOTALEDITTIME:
178 RegisterTotalTimeStyle();
179 break;
180 default:
181 break;
186 * @short: register default time style for doc field
187 * @param:
188 * @param:
190 void LwpFribDocVar::RegisterDefaultTimeStyle()
192 XFDateStyle* pDateStyle = new XFDateStyle;//use the default format
194 pDateStyle->AddMonth();
195 pDateStyle->AddText(A2OUSTR("/"));
196 pDateStyle->AddMonthDay();
197 pDateStyle->AddText(A2OUSTR("/"));
198 pDateStyle->AddYear();
199 pDateStyle->AddText(A2OUSTR(","));
200 pDateStyle->AddHour();
201 pDateStyle->AddText(A2OUSTR(":"));
202 pDateStyle->AddMinute();
203 pDateStyle->AddText(A2OUSTR(":"));
204 pDateStyle->AddSecond(sal_True,0);
206 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
207 m_TimeStyle = pXFStyleManager->AddStyle(pDateStyle)->GetStyleName();
209 void LwpFribDocVar::RegisterTotalTimeStyle()
211 XFTimeStyle* pTimeStyle = new XFTimeStyle;//use the default format
212 pTimeStyle->SetTruncate(sal_False);
213 pTimeStyle->AddMinute();
214 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
215 m_TimeStyle = pXFStyleManager->AddStyle(pTimeStyle)->GetStyleName();
219 * @short: convert the doc info field
220 * @param:
221 * @param:
223 void LwpFribDocVar::XFConvert(XFContentContainer* pXFPara)
225 XFContent* pContent=NULL;
226 switch(m_nType)
228 case FILENAME:
230 pContent = new XFFileName;
231 static_cast<XFFileName*>(pContent)->SetType(A2OUSTR("FileName"));
232 break;
234 case PATH:
236 pContent = new XFFileName;
237 static_cast<XFFileName*>(pContent)->SetType(A2OUSTR("Path"));
238 break;
240 case DESCRIPTION:
241 pContent = new XFDescription;
242 break;
243 case DATECREATED:
245 pContent = new XFCreateTime;
246 pContent->SetStyleName(m_TimeStyle);
247 break;
249 case DATELASTREVISION:
251 pContent = new XFLastEditTime;
252 pContent->SetStyleName(m_TimeStyle);
253 break;
255 case NUMPAGES:
256 pContent = new XFPageCount;
257 break;
258 case NUMWORDS:
259 pContent = new XFWordCount;
260 break;
261 case NUMCHARS:
262 pContent = new XFCharCount;
263 break;
264 case TOTALEDITTIME:
266 pContent = new XFTotalEditTime;
267 pContent->SetStyleName(m_TimeStyle);
268 break;
270 case KEYWORDS:
271 pContent = new XFKeywords;
272 break;
273 case CREATEDBY:
274 pContent = new XFInitialCreator;
275 break;
276 case DOCSIZE:
278 /* pContent = new XFAnnotation;
279 XFTextContent* pSpan = new XFTextContent();
280 pSpan->SetText(A2OUSTR("Document Size is Here"));
281 XFParagraph* pPara = new XFParagraph;
282 pPara->Add(pSpan);
283 static_cast<XFAnnotation*>(pContent)->Add(pPara);
284 break;
286 OUString text = A2OUSTR("<Document Size>");
287 LwpFrib::ConvertChars(pXFPara,text);
288 return;
290 case SMARTMASTER:
292 OUString text = A2OUSTR("<Smart master>");
293 LwpFrib::ConvertChars(pXFPara,text);
294 return;
296 case DIVISIONNAME:
298 OUString text = A2OUSTR("<Division name>");
299 LwpFrib::ConvertChars(pXFPara,text);
300 return;
302 case SECTIONNAME:
304 OUString text = A2OUSTR("<Section name>");
305 LwpFrib::ConvertChars(pXFPara,text);
306 return;
308 case VERSIONCREATEBY:
310 OUString text = A2OUSTR("<Version Creat by>");
311 LwpFrib::ConvertChars(pXFPara,text);
312 return;
314 case VERSIONCREATEDATE:
316 OUString text = A2OUSTR("<Version Creat date>");
317 LwpFrib::ConvertChars(pXFPara,text);
318 return;
320 case VERSIONOTHEREDITORS:
322 OUString text = A2OUSTR("<Version other Editors>");
323 LwpFrib::ConvertChars(pXFPara,text);
324 return;
326 case VERSIONNAME:
328 OUString text = A2OUSTR("<Version Name>");
329 LwpFrib::ConvertChars(pXFPara,text);
330 return;
332 case VERSIONNUMBER:
334 OUString text = A2OUSTR("<Version Numbers>");
335 LwpFrib::ConvertChars(pXFPara,text);
336 return;
338 case ALLVERSIONNAME:
340 OUString text = A2OUSTR("<All Version Name>");
341 LwpFrib::ConvertChars(pXFPara,text);
342 return;
344 case VERSIONREMARK:
346 OUString text = A2OUSTR("<Version Remark>");
347 LwpFrib::ConvertChars(pXFPara,text);
348 return;
350 case DOCUMENTCATEGORY:
352 OUString text = A2OUSTR("<Document Category>");
353 LwpFrib::ConvertChars(pXFPara,text);
354 return;
356 case VERSIONLASTDATE:
358 OUString text = A2OUSTR("<Version Last Modify Date>");
359 LwpFrib::ConvertChars(pXFPara,text);
360 return;
362 case VERSIONLASTEDITOR:
364 OUString text = A2OUSTR("<Version Last Editor>");
365 LwpFrib::ConvertChars(pXFPara,text);
366 return;
368 case LASTEDIT:
370 OUString text = A2OUSTR("<Last Editor>");
371 LwpFrib::ConvertChars(pXFPara,text);
372 return;
374 case OTHEREDITORS:
376 OUString text = A2OUSTR("<Other Editors>");
377 LwpFrib::ConvertChars(pXFPara,text);
378 return;
380 case NUMOFREVISION:
382 OUString text = A2OUSTR("<Number of Revision>");
383 LwpFrib::ConvertChars(pXFPara,text);
384 return;
386 default:
387 return;
389 if (m_ModFlag)//(m_pModifiers)
391 XFTextSpan *pSpan = new XFTextSpan;
392 pSpan->SetStyleName(GetStyleName());
393 pSpan->Add(pContent);
394 pXFPara->Add(pSpan);
396 else
397 pXFPara->Add(pContent);
401 * @short: Read unicode
402 * @param:
403 * @param:
405 void LwpFribUnicode::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
407 if(len>1)
409 rtl_TextEncoding rEncode;
411 if (m_pModifiers && m_pModifiers->CodePage)
412 rEncode = LwpCharSetMgr::GetInstance()->
413 GetTextCharEncoding(m_pModifiers->CodePage);
414 else
415 rEncode = LwpCharSetMgr::GetInstance()->GetTextCharEncoding();
417 LwpTools::QuickReadUnicode(pObjStrm, m_Content, len, rEncode);
420 else
421 pObjStrm->SeekRel(len);
424 void LwpFribUnicode::XFConvert(XFContentContainer* pXFPara,LwpStory* pStory)
426 if (!pStory)
427 return;
428 LwpHyperlinkMgr* pHyperlink = pStory->GetHyperlinkMgr();
429 if (pHyperlink->GetHyperlinkFlag())
430 LwpFrib::ConvertHyperLink(pXFPara,pHyperlink,GetText());
431 else
432 LwpFrib::ConvertChars(pXFPara,GetText());
436 * @short: Read page number
437 * @param:
438 * @param:
440 void LwpFribPageNumber::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
442 m_nNumStyle = pObjStrm->QuickReaduInt16();
443 m_aBefText.Read(pObjStrm);
444 m_aAfterText.Read(pObjStrm);
445 m_nStartNum = pObjStrm->QuickReaduInt16();
446 m_nStartOnPage = pObjStrm->QuickReaduInt16();
447 m_nFlag = pObjStrm->QuickReaduInt16();
450 void LwpFribPageNumber::XFConvert(XFContentContainer* pXFPara)
452 if (m_nNumStyle == 0x0)
453 return;
454 XFPageNumber* pNum = new XFPageNumber;
455 // pNum->SetSelect(A2OUSTR("current"));
456 switch(m_nNumStyle)
458 case 0x01:
459 pNum->SetNumFmt(A2OUSTR("1"));
460 break;
461 case 0x02:
462 pNum->SetNumFmt(A2OUSTR("A"));
463 break;
464 case 0x03:
465 pNum->SetNumFmt(A2OUSTR("a"));
466 break;
467 case 0x04:
468 pNum->SetNumFmt(A2OUSTR("I"));
469 break;
470 case 0x05:
471 pNum->SetNumFmt(A2OUSTR("i"));
472 break;
474 OUString styleName = GetStyleName();
475 if (m_aBefText.str().getLength()>0)
477 OUString textStr = m_aBefText.str();
478 XFTextSpan *pBef = new XFTextSpan(textStr,styleName);
479 pXFPara->Add(pBef);
481 if (m_ModFlag)//(m_pModifiers)
483 XFTextSpan *pSpan = new XFTextSpan;
484 pSpan->SetStyleName(styleName);
485 pSpan->Add(pNum);
486 pXFPara->Add(pSpan);
488 else
489 pXFPara->Add(pNum);
490 if (m_aAfterText.str().getLength()>0)
492 OUString textStr = m_aAfterText.str();
493 XFTextSpan *pAfter = new XFTextSpan(textStr,styleName);
494 pXFPara->Add(pAfter);