merge the formfield patch from ooo-build
[ooovba.git] / lotuswordpro / source / filter / lwpfrib.cxx
bloba6751275fc65ddf4360f52aedf13da3c8a969aec
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 "lwpfrib.hxx"
64 #include "lwpcharsetmgr.hxx"
65 #include "lwpsection.hxx"
66 #include "lwphyperlinkmgr.hxx"
67 #include "xfilter/xfhyperlink.hxx"
68 #include "xfilter/xfstylemanager.hxx"
69 #include "xfilter/xfsection.hxx"
70 #include "xfilter/xfsectionstyle.hxx"
71 #include "xfilter/xftextspan.hxx"
72 #include "xfilter/xftextcontent.hxx"
73 #include "lwpfribheader.hxx"
74 #include "lwpfribtext.hxx"
75 #include "lwpfribtable.hxx"
76 #include "lwpfribbreaks.hxx"
77 #include "lwpfribframe.hxx"
78 #include "lwpfribsection.hxx"
79 #include "lwpcharacterstyle.hxx"
80 #include "lwpfootnote.hxx"
81 #include "lwpnotes.hxx"
82 #include "lwpfribmark.hxx"
83 #include "lwpchangemgr.hxx"
84 #include "lwpdocdata.hxx"
85 #include "lwpglobalmgr.hxx"
87 LwpFrib::LwpFrib(LwpPara* pPara)
88 : m_pPara(pPara), m_pNext(NULL)
90 m_ModFlag = sal_False;
91 m_pModifiers = NULL;
92 m_bRevisionFlag = sal_False;
95 LwpFrib::~LwpFrib()
97 if(m_pModifiers)
98 delete m_pModifiers;
101 LwpFrib* LwpFrib::CreateFrib(LwpPara* pPara, LwpObjectStream* pObjStrm, sal_uInt8 fribtag,sal_uInt8 editID)
103 //Read Modifier
104 ModifierInfo* pModInfo = NULL;
105 if(fribtag & FRIB_TAG_MODIFIER)
107 pModInfo = new ModifierInfo();
108 pModInfo->CodePage = 0;
109 pModInfo->FontID = 0;
110 pModInfo->RevisionFlag = sal_False;
111 pModInfo->HasCharStyle = sal_False;
112 pModInfo->HasLangOverride = sal_False;
113 pModInfo->HasHighLight = sal_False;
114 ReadModifiers( pObjStrm, pModInfo );
117 //Read frib data
118 LwpFrib* newFrib = NULL;
119 sal_uInt16 friblen = pObjStrm->QuickReaduInt16();
120 sal_uInt8 fribtype = fribtag&~FRIB_TAG_TYPEMASK;
121 switch(fribtype)
123 case FRIB_TAG_INVALID: //fall through
124 case FRIB_TAG_EOP: //fall through
125 default:
126 newFrib = new LwpFrib(pPara);
127 break;
128 case FRIB_TAG_TEXT:
130 newFrib = new LwpFribText (pPara, fribtag & FRIB_TAG_NOUNICODE);
131 break;
133 case FRIB_TAG_TABLE:
134 newFrib = new LwpFribTable(pPara);
135 break;
136 case FRIB_TAG_TAB:
137 newFrib = new LwpFribTab(pPara);
138 break;
139 case FRIB_TAG_PAGEBREAK:
140 newFrib = new LwpFribPageBreak(pPara);
141 break;
142 case FRIB_TAG_FRAME:
143 newFrib = new LwpFribFrame(pPara);
144 break;
145 case FRIB_TAG_FOOTNOTE:
146 newFrib = new LwpFribFootnote(pPara);
147 break;
148 case FRIB_TAG_COLBREAK:
149 newFrib = new LwpFribColumnBreak(pPara);
150 break;
151 case FRIB_TAG_LINEBREAK:
152 newFrib = new LwpFribLineBreak(pPara);
153 break;
154 case FRIB_TAG_HARDSPACE:
155 newFrib = new LwpFribHardSpace(pPara);
156 break;
157 case FRIB_TAG_SOFTHYPHEN:
158 newFrib = new LwpFribSoftHyphen(pPara);
159 break;
160 case FRIB_TAG_PARANUMBER:
161 newFrib = new LwpFribParaNumber(pPara);
162 break;
163 case FRIB_TAG_UNICODE: //fall through
164 case FRIB_TAG_UNICODE2: //fall through
165 case FRIB_TAG_UNICODE3: //fall through
166 newFrib = new LwpFribUnicode(pPara);
167 break;
168 case FRIB_TAG_NOTE:
169 newFrib = new LwpFribNote(pPara);
170 break;
171 /* case FRIB_TAG_KANJI:
172 #ifdef KANJI
173 newFrib = new CFribHelperKanji;
174 #else
175 newFrib = new CFribHelperUnicode;
176 #endif
177 break;
178 case FRIB_TAG_HKATAKANA:
179 #ifdef KANJI
180 newFrib = new CFribHelperHKatakana;
181 #else
182 newFrib = new CFribHelperUnicode;
183 #endif
184 break;
185 case FRIB_TAG_SEPARATOR:
186 newFrib = new CFribHelperSeparator;
187 break;*/
188 case FRIB_TAG_SECTION:
189 newFrib = new LwpFribSection(pPara);
190 break;
191 /* case FRIB_TAG_TOMBSTONE:
192 newFrib = new CFribHelperTombstone;
193 break;
194 case FRIB_TAG_SPECIALTAB:
195 newFrib = new CFribHelperSpecialTab;
196 break;
197 case FRIB_TAG_PAGENUMBER:
198 newFrib = new CFribHelperPageNumber;
199 break;
200 */ case FRIB_TAG_PAGENUMBER:
201 newFrib = new LwpFribPageNumber(pPara);
202 break;
203 case FRIB_TAG_DOCVAR:
204 newFrib = new LwpFribDocVar(pPara);
205 break;
206 case FRIB_TAG_BOOKMARK:
207 newFrib = new LwpFribBookMark(pPara);
208 break;
209 /* case FRIB_TAG_DOCVAR:
210 newFrib = new CFribHelperBookmark;
211 break;
212 case FRIB_TAG_DDE:
213 newFrib = new CFribHelperDDE;
214 break;
215 */ case FRIB_TAG_FIELD:
216 newFrib = new LwpFribField(pPara);
217 break;
218 case FRIB_TAG_CHBLOCK:
219 newFrib = new LwpFribCHBlock(pPara);
220 break;
221 /* case FRIB_TAG_FLOWBREAK:
222 newFrib = new CFribHelperFlowBreak;
223 break;
224 #ifdef RUBY*/
225 case FRIB_TAG_RUBYMARKER:
226 newFrib = new LwpFribRubyMarker(pPara);
227 break;
228 case FRIB_TAG_RUBYFRAME:
229 newFrib = new LwpFribRubyFrame(pPara);
230 break;
231 /*#endif
235 //Do not know why the fribTag judgement is necessary, to be checked with
236 if ( fribtag & FRIB_TAG_MODIFIER )
238 newFrib->SetModifiers(pModInfo);
241 newFrib->SetType(fribtype);
242 newFrib->SetEditor(editID);
243 newFrib->Read(pObjStrm, friblen);
244 return newFrib;
247 void LwpFrib::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
249 pObjStrm->SeekRel(len);
252 void LwpFrib::SetModifiers(ModifierInfo* pModifiers)
254 if (pModifiers)
256 m_pModifiers = pModifiers;
257 m_ModFlag = sal_True;
258 if (pModifiers->RevisionFlag)
260 m_bRevisionFlag = sal_True;
261 m_nRevisionType = pModifiers->RevisionType;
266 void LwpFrib::RegisterStyle(LwpFoundry* pFoundry)
268 if (!m_pModifiers)
269 return;
270 if (!m_pModifiers->FontID && !m_pModifiers->HasCharStyle && !m_pModifiers->HasHighLight)
272 m_ModFlag = sal_False;
273 return;
275 //we only read four modifiers, in these modifiers,CodePage and LangOverride are not styles,
276 //so we can only handle fontid and characstyle, if others ,we should not reg style
277 //note by ,1-27
278 XFFont* pFont;
279 XFTextStyle* pStyle = NULL;
280 m_StyleName = A2OUSTR("");
281 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
282 if (m_pModifiers->HasCharStyle)
284 XFTextStyle* pNamedStyle = static_cast<XFTextStyle*>
285 (pFoundry->GetStyleManager()->GetStyle(m_pModifiers->CharStyleID));
286 if (m_pModifiers->FontID)
288 pStyle = new XFTextStyle();
289 *pStyle = *pNamedStyle;
290 LwpCharacterStyle* pCharStyle = static_cast<LwpCharacterStyle*>(m_pModifiers->CharStyleID.obj());
292 pStyle->SetStyleName(A2OUSTR(""));
293 pFont = pFoundry->GetFontManger()->CreateOverrideFont(pCharStyle->GetFinalFontID(),m_pModifiers->FontID);
294 pStyle->SetFont(pFont);
295 m_StyleName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
297 else
298 m_StyleName = pNamedStyle->GetStyleName();
300 else
302 if (m_pModifiers->FontID)
304 pStyle = new XFTextStyle();
305 pFont = pFoundry->GetFontManger()->CreateFont(m_pModifiers->FontID);
306 pStyle->SetFont(pFont);
307 m_StyleName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
311 if (m_pModifiers->HasHighLight)
313 XFColor aColor = GetHighLightColor();//right yellow
314 if (pStyle)//change the style directly
315 pStyle->GetFont()->SetBackColor(aColor);
316 else //register a new style
318 pStyle = new XFTextStyle();
320 if (m_StyleName.getLength()>0)
322 XFTextStyle* pOldStyle = pXFStyleManager->FindTextStyle(m_StyleName);
323 *pStyle = *pOldStyle;
324 pStyle->GetFont()->SetBackColor(aColor);
326 else
328 pFont = new XFFont;
329 pFont->SetBackColor(aColor);
330 pStyle->SetFont(pFont);
332 m_StyleName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
337 void LwpFrib::ReadModifiers(LwpObjectStream* pObjStrm,ModifierInfo* pModInfo)
339 sal_uInt8 Modifier;
340 sal_uInt8 len;
341 // sal_Bool ModifyFlag = sal_False;
343 for(;;)
345 // Get the modifier type
346 pObjStrm->QuickRead(&Modifier, sizeof(Modifier));
348 // Stop when we hit the last modifier
349 if (Modifier == FRIB_MTAG_NONE)
350 break;
351 // ModifyFlag = sal_True;
352 // Get the modifier length
353 pObjStrm->QuickRead(&len, sizeof(len));
355 switch (Modifier)
357 case FRIB_MTAG_FONT:
358 pObjStrm->QuickRead(&pModInfo->FontID,len);
359 break;
360 case FRIB_MTAG_CHARSTYLE:
361 pModInfo->HasCharStyle = sal_True;
362 pModInfo->CharStyleID.ReadIndexed(pObjStrm);
363 break;
364 case FRIB_MTAG_LANGUAGE:
365 pModInfo->HasLangOverride = sal_True;
366 pModInfo->Language.Read(pObjStrm);
367 break;
368 case FRIB_MTAG_CODEPAGE:
369 pObjStrm->QuickRead(&pModInfo->CodePage,len);
370 break;
371 //add by , 02/22/2005
372 case FRIB_MTAG_ATTRIBUTE:
373 pModInfo->aTxtAttrOverride.Read(pObjStrm);
374 if (pModInfo->aTxtAttrOverride.IsHighLight())
375 pModInfo->HasHighLight = sal_True;
376 break;
377 //end add
378 case FRIB_MTAG_REVISION:
379 pModInfo->RevisionType = pObjStrm->QuickReaduInt8();
380 pModInfo->RevisionFlag = sal_True;
381 break;
382 default:
383 pObjStrm->SeekRel(len);
384 break;
386 // TODO: read the modifier data
387 // pObjStrm->SeekRel(len);
393 //do nothing
394 //void LwpFrib::Parse(IXFStream* pOutputStream)
395 //{}
398 * @descr: Whether there are other fribs following current frib.
399 * @return: Ture if having following fribs, or false.
401 sal_Bool LwpFrib::HasNextFrib()
403 if (!GetNext() || GetNext()->GetType()==FRIB_TAG_EOP)
404 return sal_False;
405 return sal_True;
408 void LwpFrib::ConvertChars(XFContentContainer* pXFPara,OUString text)
410 if (m_ModFlag)
412 OUString strStyleName = GetStyleName();
413 XFTextSpan *pSpan = new XFTextSpan(text,strStyleName);
414 pXFPara->Add(pSpan);
416 else
418 XFTextContent *pSpan = new XFTextContent();
419 pSpan->SetText(text);
420 pXFPara->Add(pSpan);
424 void LwpFrib::ConvertHyperLink(XFContentContainer* pXFPara,LwpHyperlinkMgr* pHyperlink,OUString text)
426 XFHyperlink* pHyper = new XFHyperlink;
427 pHyper->SetHRef(pHyperlink->GetHyperlink());
428 pHyper->SetText(text);
429 pHyper->SetStyleName(GetStyleName());
430 pXFPara->Add(pHyper);
434 * @descr: Get the current frib font style
435 * @return: XFFont pointer
437 XFFont* LwpFrib::GetFont()
439 XFFont* pFont = NULL;
440 if(m_pModifiers&&m_pModifiers->FontID)
442 LwpFoundry* pFoundry = m_pPara->GetFoundry();
443 pFont = pFoundry->GetFontManger()->CreateFont(m_pModifiers->FontID);
445 else
447 XFParaStyle* pXFParaStyle = m_pPara->GetXFParaStyle();
448 pFont = pXFParaStyle->GetFont();
450 return pFont;
453 OUString LwpFrib::GetEditor()
455 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
456 return pGlobal->GetEditorName(m_nEditor);
459 XFColor LwpFrib::GetHighLightColor()
461 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
462 return pGlobal->GetHighLightColor(m_nEditor);