1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27
28 #include <svl/itemiter.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/outdev.hxx>
31
32 #include <toolkit/helper/vclunohelper.hxx>
33 #include <com/sun/star/form/XFormsSupplier.hpp>
34 #include <com/sun/star/form/XForm.hpp>
35 #include <com/sun/star/form/XImageProducerSupplier.hpp>
36 #include <com/sun/star/form/XFormController.hpp>
37 #include <com/sun/star/frame/XStorable.hpp>
38 #include <com/sun/star/frame/XModel.hpp>
39 #include <com/sun/star/drawing/XConnectableShape.hpp>
40 #include <com/sun/star/drawing/XConnectorShape.hpp>
41 #include <com/sun/star/drawing/XShape.hpp>
42 #include <com/sun/star/drawing/XControlShape.hpp>
43 #include <com/sun/star/drawing/XShapeAligner.hpp>
44 #include <com/sun/star/drawing/XShapeGroup.hpp>
45 #include <com/sun/star/drawing/XUniversalShapeDescriptor.hpp>
46 #include <com/sun/star/drawing/XShapeMirror.hpp>
47 #include <com/sun/star/drawing/XShapeArranger.hpp>
48 #include <com/sun/star/drawing/XDrawPage.hpp>
49 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
52 #include <com/sun/star/container/XIndexContainer.hpp>
53 #include <com/sun/star/text/VertOrientation.hpp>
54 #include <com/sun/star/text/TextContentAnchorType.hpp>
55 #include <comphelper/extract.hxx>
56 #include <comphelper/stlunosequence.hxx>
57 #include <com/sun/star/beans/XPropertyContainer.hpp>
58 #include <com/sun/star/beans/PropertyAttribute.hpp>
59
60 #include <algorithm>
61 #include <functional>
62 #include <hintids.hxx>
63 #include <editeng/fontitem.hxx>
64 #include <editeng/lrspitem.hxx>
65 #include <editeng/fhgtitem.hxx>
66 #include <editeng/colritem.hxx>
67 #include <editeng/wghtitem.hxx>
68 #include <editeng/crsditem.hxx>
69 #include <editeng/udlnitem.hxx>
70 #include <editeng/postitem.hxx>
71 #include <filter/msfilter/msocximex.hxx>
72 #include <errhdl.hxx>
73 #include <unotextrange.hxx>
74 #include <doc.hxx>
75 #include <docary.hxx>
76 #include <docsh.hxx>
77 #include <numrule.hxx>
78 #include <paratr.hxx>
79 #include <charatr.hxx>
80 #include <charfmt.hxx>
81 #include <ndtxt.hxx>
82 #include <expfld.hxx>
83 #include <fmtfld.hxx>
84 #include <flddropdown.hxx>
85 #include "writerhelper.hxx"
86 #include "writerwordglue.hxx"
87 #include "ww8par.hxx"
88 #include "ww8par2.hxx" // wg. Listen-Attributen in Styles
89
90 #include <IMark.hxx>
91 #include <unotools/fltrcfg.hxx>
92 #include <xmloff/odffields.hxx>
93
94 #include <stdio.h>
95 #include <algorithm>
96
97 using namespace com::sun::star;
98 using namespace sw::util;
99 using namespace sw::types;
100 using namespace sw::mark;
101
102 //-----------------------------------------
103 // UNO-Controls
104 //-----------------------------------------
105
106 //cmc, OCX i.e. Word 97 form controls
Read_F_OCX(WW8FieldDesc *,String &)107 eF_ResT SwWW8ImplReader::Read_F_OCX( WW8FieldDesc*, String& )
108 {
109 if( bObj && nPicLocFc )
110 nObjLocFc = nPicLocFc;
111 bEmbeddObj = true;
112 return FLD_TEXT;
113 }
114
Read_F_FormTextBox(WW8FieldDesc * pF,String & rStr)115 eF_ResT SwWW8ImplReader::Read_F_FormTextBox( WW8FieldDesc* pF, String& rStr )
116 {
117 WW8FormulaEditBox aFormula(*this);
118
119 if (0x01 == rStr.GetChar(writer_cast<xub_StrLen>(pF->nLCode-1))) {
120 ImportFormulaControl(aFormula,pF->nSCode+pF->nLCode-1, WW8_CT_EDIT);
121 }
122
123 /* #80205#
124 Here we have a small complication. This formula control contains
125 the default text that is displayed if you edit the form field in
126 the "default text" area. But MS Office does not display that
127 information, instead it display the result of the field,
128 MS Office just uses the default text of the control as its
129 initial value for the displayed default text. So we will swap in
130 the field result into the formula here in place of the default
131 text.
132 */
133
134 const SvtFilterOptions* pOpt = SvtFilterOptions::Get();
135 const sal_Bool bUseEnhFields=(pOpt && pOpt->IsUseEnhancedFields());
136
137 if (!bUseEnhFields)
138 {
139 aFormula.sDefault = GetFieldResult(pF);
140
141 #if 0 // why not? (flr)
142 //substituting Unicode spacing 0x2002 with double space for layout
143 aFormula.sDefault.SearchAndReplaceAll(
144 String(static_cast< sal_Unicode >(0x2002)),
145 CREATE_CONST_ASC(" "));
146 #endif
147
148 SwInputField aFld(
149 static_cast<SwInputFieldType*>(rDoc.GetSysFldType( RES_INPUTFLD )),
150 aFormula.sDefault,
151 aFormula.sTitle,
152 INP_TXT,
153 0 );
154 aFld.SetHelp(aFormula.sHelp);
155 aFld.SetToolTip(aFormula.sToolTip);
156
157 rDoc.InsertPoolItem( *pPaM, SwFmtFld(aFld), 0 );
158 return FLD_OK;
159 }
160 else
161 {
162 WW8PLCFx_Book* pB = pPlcxMan->GetBook();
163 String aBookmarkName;
164 if (pB!=NULL) {
165 WW8_CP currentCP=pF->nSCode;
166 WW8_CP currentLen=pF->nLen;
167
168 sal_uInt16 bkmFindIdx;
169 String aBookmarkFind=pB->GetBookmark(currentCP-1, currentCP+currentLen-1, bkmFindIdx);
170
171 if (aBookmarkFind.Len()>0) {
172 pB->SetStatus(bkmFindIdx, BOOK_FIELD); // mark bookmark as consumed, such that it will not get inserted as a "normal" bookmark again
173 if (aBookmarkFind.Len()>0) {
174 aBookmarkName=aBookmarkFind;
175 }
176 }
177 }
178
179 if (pB!=NULL && aBookmarkName.Len()==0) {
180 aBookmarkName=pB->GetUniqueBookmarkName(aFormula.sTitle);
181 }
182
183
184 if (aBookmarkName.Len()>0) {
185 maFieldStack.back().SetBookmarkName(aBookmarkName);
186 maFieldStack.back().SetBookmarkType(::rtl::OUString::createFromAscii(ODF_FORMTEXT));
187 maFieldStack.back().getParameters()[::rtl::OUString::createFromAscii("Description")] = uno::makeAny(::rtl::OUString(aFormula.sToolTip));
188 maFieldStack.back().getParameters()[::rtl::OUString::createFromAscii("Name")] = uno::makeAny(::rtl::OUString(aFormula.sTitle));
189 }
190 return FLD_TEXT;
191 }
192 }
193
Read_F_FormCheckBox(WW8FieldDesc * pF,String & rStr)194 eF_ResT SwWW8ImplReader::Read_F_FormCheckBox( WW8FieldDesc* pF, String& rStr )
195 {
196 WW8FormulaCheckBox aFormula(*this);
197
198 if (!pFormImpl)
199 pFormImpl = new SwMSConvertControls(mpDocShell, pPaM);
200
201 if (0x01 == rStr.GetChar(writer_cast<xub_StrLen>(pF->nLCode-1)))
202 ImportFormulaControl(aFormula,pF->nSCode+pF->nLCode-1, WW8_CT_CHECKBOX);
203 const SvtFilterOptions* pOpt = SvtFilterOptions::Get();
204 sal_Bool bUseEnhFields=(pOpt && pOpt->IsUseEnhancedFields());
205
206 if (!bUseEnhFields)
207 {
208 pFormImpl->InsertFormula(aFormula);
209 return FLD_OK;
210 }
211 else
212 {
213 String aBookmarkName;
214 WW8PLCFx_Book* pB = pPlcxMan->GetBook();
215 if (pB!=NULL) {
216 WW8_CP currentCP=pF->nSCode;
217 WW8_CP currentLen=pF->nLen;
218
219 sal_uInt16 bkmFindIdx;
220 String aBookmarkFind=pB->GetBookmark(currentCP-1, currentCP+currentLen-1, bkmFindIdx);
221
222 if (aBookmarkFind.Len()>0) {
223 pB->SetStatus(bkmFindIdx, BOOK_FIELD); // mark as consumed by field
224 if (aBookmarkFind.Len()>0) {
225 aBookmarkName=aBookmarkFind;
226 }
227 }
228 }
229
230 if (pB!=NULL && aBookmarkName.Len()==0) {
231 aBookmarkName=pB->GetUniqueBookmarkName(aFormula.sTitle);
232 }
233
234 if (aBookmarkName.Len()>0)
235 {
236 IDocumentMarkAccess* pMarksAccess = rDoc.getIDocumentMarkAccess( );
237 IFieldmark* pFieldmark = dynamic_cast<IFieldmark*>( pMarksAccess->makeNoTextFieldBookmark(
238 *pPaM, aBookmarkName,
239 rtl::OUString::createFromAscii( ODF_FORMCHECKBOX ) ) );
240 ASSERT(pFieldmark!=NULL, "hmmm; why was the bookmark not created?");
241 if (pFieldmark!=NULL) {
242 IFieldmark::parameter_map_t* const pParameters = pFieldmark->GetParameters();
243 ICheckboxFieldmark* pCheckboxFm = dynamic_cast<ICheckboxFieldmark*>(pFieldmark);
244 (*pParameters)[::rtl::OUString::createFromAscii(ODF_FORMCHECKBOX_NAME)] = uno::makeAny(::rtl::OUString(aFormula.sTitle));
245 (*pParameters)[::rtl::OUString::createFromAscii(ODF_FORMCHECKBOX_HELPTEXT)] = uno::makeAny(::rtl::OUString(aFormula.sToolTip));
246 if(pCheckboxFm)
247 pCheckboxFm->SetChecked(aFormula.nChecked);
248 // set field data here...
249 }
250 }
251 return FLD_OK;
252 }
253 }
254
Read_F_FormListBox(WW8FieldDesc * pF,String & rStr)255 eF_ResT SwWW8ImplReader::Read_F_FormListBox( WW8FieldDesc* pF, String& rStr)
256 {
257 WW8FormulaListBox aFormula(*this);
258
259 if (0x01 == rStr.GetChar(writer_cast<xub_StrLen>(pF->nLCode-1)))
260 ImportFormulaControl(aFormula,pF->nSCode+pF->nLCode-1, WW8_CT_DROPDOWN);
261
262 const SvtFilterOptions* pOpt = SvtFilterOptions::Get();
263 sal_Bool bUseEnhFields=(pOpt && pOpt->IsUseEnhancedFields());
264
265 if (!bUseEnhFields)
266 {
267 SwDropDownField aFld((SwDropDownFieldType*)rDoc.GetSysFldType(RES_DROPDOWN));
268
269 aFld.SetName(aFormula.sTitle);
270 aFld.SetHelp(aFormula.sHelp);
271 aFld.SetToolTip(aFormula.sToolTip);
272
273 if (!aFormula.maListEntries.empty())
274 {
275 aFld.SetItems(aFormula.maListEntries);
276 int nIndex = aFormula.fDropdownIndex < aFormula.maListEntries.size() ? aFormula.fDropdownIndex : 0;
277 aFld.SetSelectedItem(aFormula.maListEntries[nIndex]);
278 }
279
280 rDoc.InsertPoolItem(*pPaM, SwFmtFld(aFld), 0);
281 return FLD_OK;
282 }
283 else
284 {
285 // TODO: review me
286 String aBookmarkName;
287 WW8PLCFx_Book* pB = pPlcxMan->GetBook();
288 if (pB!=NULL)
289 {
290 WW8_CP currentCP=pF->nSCode;
291 WW8_CP currentLen=pF->nLen;
292
293 sal_uInt16 bkmFindIdx;
294 String aBookmarkFind=pB->GetBookmark(currentCP-1, currentCP+currentLen-1, bkmFindIdx);
295
296 if (aBookmarkFind.Len()>0)
297 {
298 pB->SetStatus(bkmFindIdx, BOOK_FIELD); // mark as consumed by field
299 if (aBookmarkFind.Len()>0)
300 aBookmarkName=aBookmarkFind;
301 }
302 }
303
304 if (pB!=NULL && aBookmarkName.Len()==0)
305 aBookmarkName=pB->GetUniqueBookmarkName(aFormula.sTitle);
306
307 if (aBookmarkName.Len()>0)
308 {
309 IDocumentMarkAccess* pMarksAccess = rDoc.getIDocumentMarkAccess( );
310 IFieldmark *pFieldmark = dynamic_cast<IFieldmark*>(
311 pMarksAccess->makeNoTextFieldBookmark( *pPaM, aBookmarkName,
312 ::rtl::OUString::createFromAscii( ODF_FORMDROPDOWN ) ) );
313 ASSERT(pFieldmark!=NULL, "hmmm; why was the bookmark not created?");
314 if ( pFieldmark != NULL )
315 {
316 uno::Sequence< ::rtl::OUString > vListEntries(aFormula.maListEntries.size());
317 ::std::copy(aFormula.maListEntries.begin(), aFormula.maListEntries.end(), ::comphelper::stl_begin(vListEntries));
318 (*pFieldmark->GetParameters())[::rtl::OUString::createFromAscii(ODF_FORMDROPDOWN_LISTENTRY)] = uno::makeAny(vListEntries);
319 sal_Int32 nIndex = aFormula.fDropdownIndex < aFormula.maListEntries.size() ? aFormula.fDropdownIndex : 0;
320 (*pFieldmark->GetParameters())[::rtl::OUString::createFromAscii(ODF_FORMDROPDOWN_RESULT)] = uno::makeAny(nIndex);
321 // set field data here...
322 }
323 }
324
325 return FLD_OK;
326 }
327 }
328
DeleteFormImpl()329 void SwWW8ImplReader::DeleteFormImpl()
330 {
331 delete pFormImpl, pFormImpl = 0;
332 }
333
334 //----------------------------------------------------------------------------
335 // WW8ListManager oeffentliche Methoden stehen ganz am Ende
336 //------------------------- ============ --------------- ============ --------
337
338
339
340 // Hilfs-Deklarationen ///////////////////////////////////////////////////////
341 //
342 // Style Id's for each level
343 typedef sal_uInt16 WW8aIdSty[WW8ListManager::nMaxLevel];
344 // Zeichenattribute aus GrpprlChpx
345 typedef SfxItemSet* WW8aISet[WW8ListManager::nMaxLevel];
346 // Zeichen Style Pointer
347 typedef SwCharFmt* WW8aCFmt[WW8ListManager::nMaxLevel];
348
349 struct WW8LST // nur DIE Eintraege, die WIR benoetigen!
350 {
351 WW8aIdSty aIdSty; // Style Id's for each level,
352 // nIStDNil if no style linked
353 sal_uInt32 nIdLst; // Unique List ID
354 sal_uInt32 nTplC; // Unique template code - Was ist das bloss?
355 sal_uInt8 bSimpleList:1; // Flag: Liste hat nur EINEN Level
356 sal_uInt8 bRestartHdn:1; // WW6-Kompatibilitaets-Flag:
357 // true if the list should start numbering over
358 }; // at the beginning of each section
359
360 struct WW8LFO // nur DIE Eintraege, die WIR benoetigen!
361 {
362 SwNumRule* pNumRule; // Parent NumRule
363 sal_uInt32 nIdLst; // Unique List ID
364 sal_uInt8 nLfoLvl; // count of levels whose format is overridden
365 bool bSimpleList;
366 };
367
368 struct WW8LVL // nur DIE Eintraege, die WIR benoetigen!
369 {
370 long nStartAt; // start at value for this value
371 long nV6DxaSpace;// Ver6-Compatible: min Space between Num anf text::Paragraph
372 long nV6Indent; // Ver6-Compatible: Breite des Prefix Textes; ggfs. zur
373 // Definition d. Erstzl.einzug nutzen!
374 // Absatzattribute aus GrpprlPapx
375 sal_uInt16 nDxaLeft; // linker Einzug
376 short nDxaLeft1; // Erstzeilen-Einzug
377
378 sal_uInt8 nNFC; // number format code
379 // Offset der Feldkodes im Num-X-String
380 sal_uInt8 aOfsNumsXCH[WW8ListManager::nMaxLevel];
381 sal_uInt8 nLenGrpprlChpx; // length, in bytes, of the LVL's grpprlChpx
382 sal_uInt8 nLenGrpprlPapx; // length, in bytes, of the LVL's grpprlPapx
383 sal_uInt8 nAlign: 2; // alignment (left, right, centered) of the number
384 sal_uInt8 bLegal: 1; // egal
385 sal_uInt8 bNoRest:1; // egal
386 sal_uInt8 bV6Prev:1; // Ver6-Compatible: number will include previous levels
387 sal_uInt8 bV6PrSp:1; // Ver6-Compatible: egal
388 sal_uInt8 bV6: 1; // falls true , beachte die V6-Compatible Eintraege!
389 sal_uInt8 bDummy: 1; // (macht das Byte voll)
390
391 };
392
393 struct WW8LFOLVL
394 {
395 long nStartAt; // start-at value if bFormat==false and bStartAt == true
396 // (if bFormat==true, the start-at is stored in the LVL)
397 sal_uInt8 nLevel; // the level to be overridden
398 // dieses Byte ist _absichtlich_ nicht in das folgende Byte hineingepackt!
399 // (siehe Kommentar unten bei struct WW8LFOInfo)
400
401 sal_uInt8 bStartAt :1; // true if the start-at value is overridden
402 sal_uInt8 bFormat :1; // true if the formatting is overridden
403
WW8LFOLVLWW8LFOLVL404 WW8LFOLVL() :
405 nStartAt(1), nLevel(0), bStartAt(1), bFormat(0) {}
406 };
407
408 // in den ListenInfos zu speichernde Daten ///////////////////////////////////
409 //
410 struct WW8LSTInfo // sortiert nach nIdLst (in WW8 verwendete Listen-Id)
411 {
412 std::vector<ww::bytes> maParaSprms;
413 WW8aIdSty aIdSty; // Style Id's for each level
414 WW8aISet aItemSet; // Zeichenattribute aus GrpprlChpx
415 WW8aCFmt aCharFmt; // Zeichen Style Pointer
416
417 SwNumRule* pNumRule; // Zeiger auf entsprechende Listenvorlage im Writer
418 sal_uInt32 nIdLst; // WW8Id dieser Liste
419 sal_uInt8 bSimpleList:1;// Flag, ob diese NumRule nur einen Level verwendet
420 sal_uInt8 bUsedInDoc :1;// Flag, ob diese NumRule im Doc verwendet wird,
421 // oder beim Reader-Ende geloescht werden sollte
422
WW8LSTInfoWW8LSTInfo423 WW8LSTInfo(SwNumRule* pNumRule_, WW8LST& aLST)
424 : pNumRule(pNumRule_), nIdLst(aLST.nIdLst),
425 bSimpleList(aLST.bSimpleList), bUsedInDoc(0)
426 {
427 memcpy( aIdSty, aLST.aIdSty, sizeof( aIdSty ));
428 memset(&aItemSet, 0, sizeof( aItemSet ));
429 memset(&aCharFmt, 0, sizeof( aCharFmt ));
430 }
431
432 };
433
434 // in den ListenFormatOverrideInfos zu speichernde Daten /////////////////////
435 //
436 struct WW8LFOInfo // unsortiert, d.h. Reihenfolge genau wie im WW8 Stream
437 {
438 std::vector<ww::bytes> maParaSprms;
439 std::vector<WW8LFOLVL> maOverrides;
440 SwNumRule* pNumRule; // Zeiger auf entsprechende Listenvorlage im Writer
441 // entweder: Liste in LSTInfos oder eigene Liste
442 // (im Ctor erstmal die aus den LSTInfos merken)
443
444 sal_uInt32 nIdLst; // WW8-Id der betreffenden Liste
445 sal_uInt8 nLfoLvl; // count of levels whose format is overridden
446 // Ja, ich natuerlich koennten wir nLfoLvl (mittels :4) noch in das folgende
447 // Byte mit hineinpacken, doch waere das eine ziemliche Fehlerquelle,
448 // an dem Tag, wo MS ihr Listenformat auf mehr als 15 Level aufbohren.
449
450 sal_uInt8 bOverride :1;// Flag, ob die NumRule nicht in maLSTInfos steht,
451 // sondern fuer pLFOInfos NEU angelegt wurde
452 sal_uInt8 bSimpleList:1;// Flag, ob diese NumRule nur einen Level verwendet
453 sal_uInt8 bUsedInDoc :1;// Flag, ob diese NumRule im Doc verwendet wird,
454 // oder beim Reader-Ende geloescht werden sollte
455 sal_uInt8 bLSTbUIDSet :1;// Flag, ob bUsedInDoc in maLSTInfos gesetzt wurde,
456 // und nicht nochmals gesetzt zu werden braucht
457 WW8LFOInfo(const WW8LFO& rLFO);
458 };
459
WW8LFOInfo(const WW8LFO & rLFO)460 WW8LFOInfo::WW8LFOInfo(const WW8LFO& rLFO)
461 : maParaSprms(WW8ListManager::nMaxLevel)
462 , maOverrides(WW8ListManager::nMaxLevel)
463 , pNumRule(rLFO.pNumRule)
464 , nIdLst(rLFO.nIdLst)
465 , nLfoLvl(rLFO.nLfoLvl)
466 , bOverride(rLFO.nLfoLvl ? true : false)
467 , bSimpleList(rLFO.bSimpleList)
468 , bUsedInDoc(0)
469 , bLSTbUIDSet(0)
470 {
471 }
472
473 SV_IMPL_PTRARR( WW8LFOInfos, WW8LFOInfo_Ptr );
474
475
476 // Hilfs-Methoden ////////////////////////////////////////////////////////////
477 //
478
479 // finden der Sprm-Parameter-Daten, falls Sprm im Grpprl enthalten
GrpprlHasSprm(sal_uInt16 nId,sal_uInt8 & rSprms,sal_uInt8 nLen)480 sal_uInt8* WW8ListManager::GrpprlHasSprm(sal_uInt16 nId, sal_uInt8& rSprms,
481 sal_uInt8 nLen)
482 {
483 sal_uInt8* pSprms = &rSprms;
484 sal_uInt16 i=0;
485 while (i < nLen)
486 {
487 sal_uInt16 nAktId = maSprmParser.GetSprmId(pSprms);
488 if( nAktId == nId ) // Sprm found
489 return pSprms + maSprmParser.DistanceToData(nId);
490
491 // gib Zeiger auf Daten
492 sal_uInt16 x = maSprmParser.GetSprmSize(nAktId, pSprms);
493 i = i + x;
494 pSprms += x;
495 }
496 return 0; // Sprm not found
497 }
498
499 class ListWithId
500 {
501 public:
502 typedef const WW8LSTInfo * argument_type;
503 typedef bool result_type;
504 private:
505 private:
506 sal_uInt32 mnIdLst;
507 public:
ListWithId(sal_uInt32 nIdLst)508 explicit ListWithId(sal_uInt32 nIdLst) : mnIdLst(nIdLst) {}
operator ()(const WW8LSTInfo * pEntry) const509 bool operator() (const WW8LSTInfo *pEntry) const
510 { return (pEntry->nIdLst == mnIdLst); }
511 };
512
513 // Zugriff ueber die List-Id des LST Eintrags
GetLSTByListId(sal_uInt32 nIdLst) const514 WW8LSTInfo* WW8ListManager::GetLSTByListId( sal_uInt32 nIdLst ) const
515 {
516 std::vector<WW8LSTInfo *>::const_iterator aResult =
517 std::find_if(maLSTInfos.begin(),maLSTInfos.end(),ListWithId(nIdLst));
518 if (aResult == maLSTInfos.end())
519 return 0;
520 return *aResult;
521 }
522
lcl_CopyGreaterEight(String & rDest,String & rSrc,xub_StrLen nStart,xub_StrLen nLen=STRING_LEN)523 void lcl_CopyGreaterEight(String &rDest, String &rSrc,
524 xub_StrLen nStart, xub_StrLen nLen = STRING_LEN)
525 {
526 if (nLen == STRING_LEN)
527 nLen = rSrc.Len();
528 for (xub_StrLen nI = nStart; nI < nLen; ++nI)
529 {
530 sal_Unicode nChar = rSrc.GetChar(nI);
531 if (nChar > WW8ListManager::nMaxLevel)
532 rDest.Append(nChar);
533 }
534 }
535
ReadLVL(SwNumFmt & rNumFmt,SfxItemSet * & rpItemSet,sal_uInt16 nLevelStyle,bool bSetStartNo,std::deque<bool> & rNotReallyThere,sal_uInt16 nLevel,ww::bytes & rParaSprms)536 bool WW8ListManager::ReadLVL(
537 SwNumFmt& rNumFmt,
538 SfxItemSet*& rpItemSet,
539 sal_uInt16 nLevelStyle,
540 bool bSetStartNo,
541 std::deque< bool > &rNotReallyThere,
542 sal_uInt16 nLevel,
543 ww::bytes &rParaSprms )
544 {
545 sal_uInt8 aBits1;
546 sal_uInt16 nStartNo = 0; // Start-Nr. fuer den Writer
547 sal_Int16 nType(style::NumberingType::ARABIC);
548 SvxAdjust eAdj; // Ausrichtung (Links/rechts/zent.)
549 sal_Unicode cBullet(0x2190); // default safe bullet
550
551 sal_Unicode cGrfBulletCP(USHRT_MAX);
552
553 String sPrefix;
554 String sPostfix;
555 WW8LVL aLVL;
556 //
557 // 1. LVLF einlesen
558 //
559 memset(&aLVL, 0, sizeof( aLVL ));
560 rSt >> aLVL.nStartAt;
561 rSt >> aLVL.nNFC;
562 rSt >> aBits1;
563 if( 0 != rSt.GetError() ) return false;
564 aLVL.nAlign = (aBits1 & 0x03);
565 if( aBits1 & 0x10 ) aLVL.bV6Prev = true;
566 if( aBits1 & 0x20 ) aLVL.bV6PrSp = true;
567 if( aBits1 & 0x40 ) aLVL.bV6 = true;
568 bool bLVLOkB = true;
569 sal_uInt8 nLevelB = 0;
570 for(nLevelB = 0; nLevelB < nMaxLevel; ++nLevelB)
571 {
572 rSt >> aLVL.aOfsNumsXCH[ nLevelB ];
573 if( 0 != rSt.GetError() )
574 {
575 bLVLOkB = false;
576 break;
577 }
578 }
579
580 if( !bLVLOkB )
581 return false;
582
583 sal_uInt8 ixchFollow;
584 rSt >> ixchFollow;
585 if (ixchFollow == 0)
586 rReader.maTracer.Log(sw::log::eTabInNumbering);
587 rSt >> aLVL.nV6DxaSpace;
588 rSt >> aLVL.nV6Indent;
589 rSt >> aLVL.nLenGrpprlChpx;
590 rSt >> aLVL.nLenGrpprlPapx;
591 rSt.SeekRel( 2 );
592 if( 0 != rSt.GetError()) return false;
593
594 //
595 // 2. ggfs. PAPx einlesen und nach Einzug-Werten suchen
596 //
597 // --> OD 2008-06-04 #i86652# - read tab setting
598 short nTabPos = 0;
599 // <--
600 if( aLVL.nLenGrpprlPapx )
601 {
602 sal_uInt8 aGrpprlPapx[ 255 ];
603 if(aLVL.nLenGrpprlPapx != rSt.Read(&aGrpprlPapx,aLVL.nLenGrpprlPapx))
604 return false;
605 // "sprmPDxaLeft" pap.dxaLeft;dxa;word;
606 sal_uInt8* pSprm;
607 if (
608 (0 != (pSprm = GrpprlHasSprm(0x840F,aGrpprlPapx[0],aLVL.nLenGrpprlPapx))) ||
609 (0 != (pSprm = GrpprlHasSprm(0x845E,aGrpprlPapx[0],aLVL.nLenGrpprlPapx)))
610 )
611 {
612 sal_uInt8 *pBegin = pSprm-2;
613 for(int i=0;i<4;++i)
614 rParaSprms.push_back(*pBegin++);
615 short nDxaLeft = SVBT16ToShort( pSprm );
616 aLVL.nDxaLeft = (0 < nDxaLeft) ? (sal_uInt16)nDxaLeft
617 : (sal_uInt16)(-nDxaLeft);
618 }
619
620 // "sprmPDxaLeft1" pap.dxaLeft1;dxa;word;
621 if (
622 (0 != (pSprm = GrpprlHasSprm(0x8411,aGrpprlPapx[0],aLVL.nLenGrpprlPapx)) ) ||
623 (0 != (pSprm = GrpprlHasSprm(0x8460,aGrpprlPapx[0],aLVL.nLenGrpprlPapx)) )
624 )
625 {
626 sal_uInt8 *pBegin = pSprm-2;
627 for(int i=0;i<4;++i)
628 rParaSprms.push_back(*pBegin++);
629 aLVL.nDxaLeft1 = SVBT16ToShort( pSprm );
630 }
631
632 // --> OD 2008-06-04 #i86652# - read tab setting
633 if(0 != (pSprm = GrpprlHasSprm(0xC615,aGrpprlPapx[0],aLVL.nLenGrpprlPapx)) )
634 {
635 bool bDone = false;
636 if (*(pSprm-1) == 5)
637 {
638 if (*pSprm++ == 0) //nDel
639 {
640 if (*pSprm++ == 1) //nIns
641 {
642 nTabPos = SVBT16ToShort(pSprm);
643 pSprm+=2;
644 if (*pSprm == 6) //type
645 {
646 bDone = true;
647 }
648 }
649 }
650 }
651 ASSERT(bDone, "tab setting in numbering is "
652 "of unexpected configuration");
653 }
654 if ( rNumFmt.GetPositionAndSpaceMode() ==
655 SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
656 {
657 // If there is a tab setting with a larger value, then use that.
658 // Ideally we would allow tabs to be used in numbering fields and set
659 // this on the containing paragraph which would make it actually work
660 // most of the time.
661 if ( nTabPos != 0 )
662 {
663 const sal_uInt16 nDesired = aLVL.nDxaLeft + aLVL.nDxaLeft1;
664
665 bool bDoAdjust = false;
666 if ( nDesired < aLVL.nDxaLeft )
667 {
668 if ( nDesired < nTabPos && nTabPos < aLVL.nDxaLeft )
669 {
670 bDoAdjust = true;
671 }
672 }
673 else
674 {
675 if ( aLVL.nDxaLeft < nTabPos && nTabPos < nDesired )
676 {
677 bDoAdjust = true;
678 }
679 }
680
681 if (bDoAdjust)
682 {
683 aLVL.nDxaLeft = (0 < nTabPos)
684 ? (sal_uInt16)nTabPos
685 : (sal_uInt16)(-nTabPos);
686
687 aLVL.nDxaLeft1 = nDesired - aLVL.nDxaLeft;
688 }
689 }
690 }
691 // <--
692 }
693 //
694 // 3. ggfs. CHPx einlesen und
695 //
696 sal_uInt16 nWitchPicIsBullet = USHRT_MAX;
697 bool bIsPicBullet = false;
698
699 if( aLVL.nLenGrpprlChpx )
700 {
701 sal_uInt8 aGrpprlChpx[ 255 ];
702 memset(&aGrpprlChpx, 0, sizeof( aGrpprlChpx ));
703 if(aLVL.nLenGrpprlChpx != rSt.Read(&aGrpprlChpx, aLVL.nLenGrpprlChpx))
704 return false;
705
706 //For i120928,parse the graphic info of bullets
707 sal_uInt8 *pSprmWhichPis = GrpprlHasSprm(0x6887,aGrpprlChpx[0],aLVL.nLenGrpprlChpx);
708 sal_uInt8 *pSprmIsPicBullet = GrpprlHasSprm(0x4888,aGrpprlChpx[0],aLVL.nLenGrpprlChpx);
709 if (pSprmWhichPis)
710 {
711 nWitchPicIsBullet = *pSprmWhichPis;
712 }
713 if (pSprmIsPicBullet)
714 {
715 bIsPicBullet = (*pSprmIsPicBullet) & 0x0001;
716 }
717
718 // neues ItemSet fuer die Zeichenattribute anlegen
719 rpItemSet = new SfxItemSet( rDoc.GetAttrPool(), RES_CHRATR_BEGIN,
720 RES_CHRATR_END - 1 );
721
722 // Reader-ItemSet-Pointer darauf zeigen lassen
723 rReader.SetAktItemSet( rpItemSet );
724 // Reader-Style auf den Style dieses Levels setzen
725 sal_uInt16 nOldColl = rReader.GetNAktColl();
726 sal_uInt16 nNewColl = nLevelStyle;
727 if (ww::stiNil == nNewColl)
728 nNewColl = 0;
729 rReader.SetNAktColl( nNewColl );
730
731 // Nun den GrpprlChpx einfach durchnudeln: die Read_xy() Methoden
732 // in WW8PAR6.CXX rufen ganz normal ihr NewAttr() oder GetFmtAttr()
733 // und diese merken am besetzten Reader-ItemSet-Pointer, dass dieser
734 // spezielle ItemSet relevant ist - und nicht ein Stack oder Style!
735 sal_uInt16 nOldFlags1 = rReader.GetToggleAttrFlags();
736 sal_uInt16 nOldFlags2 = rReader.GetToggleBiDiAttrFlags();
737 short nLen = aLVL.nLenGrpprlChpx;
738 sal_uInt8* pSprms1 = &aGrpprlChpx[0];
739 while (0 < nLen)
740 {
741 sal_uInt16 nL1 = rReader.ImportSprm( pSprms1 );
742 nLen = nLen - nL1;
743 pSprms1 += nL1;
744 }
745 // Reader-ItemSet-Pointer und Reader-Style zuruecksetzen
746 rReader.SetAktItemSet( 0 );
747 rReader.SetNAktColl( nOldColl );
748 rReader.SetToggleAttrFlags(nOldFlags1);
749 rReader.SetToggleBiDiAttrFlags(nOldFlags2);
750 }
751 //
752 // 4. den Nummerierungsstring einlesen: ergibt Prefix und Postfix
753 //
754 String sNumString(WW8Read_xstz(rSt, 0, false));
755 //
756 // 5. gelesene Werte in Writer Syntax umwandeln
757 //
758 if( 0 <= aLVL.nStartAt )
759 nStartNo = (sal_uInt16)aLVL.nStartAt;
760 switch( aLVL.nNFC )
761 {
762 case 0:
763 nType = style::NumberingType::ARABIC;
764 break;
765 case 1:
766 nType = style::NumberingType::ROMAN_UPPER;
767 break;
768 case 2:
769 nType = style::NumberingType::ROMAN_LOWER;
770 break;
771 case 3:
772 nType = style::NumberingType::CHARS_UPPER_LETTER_N;
773 break;
774 case 4:
775 nType = style::NumberingType::CHARS_LOWER_LETTER_N;
776 break;
777 case 5:
778 // eigentlich: ORDINAL
779 nType = style::NumberingType::ARABIC;
780 break;
781 case 23:
782 nType = style::NumberingType::CHAR_SPECIAL;
783 //For i120928,type info
784 if (bIsPicBullet)
785 {
786 nType = style::NumberingType::BITMAP;
787 }
788
789 break;
790 case 255:
791 nType = style::NumberingType::NUMBER_NONE;
792 break;
793 case 18: nType = style::NumberingType::CIRCLE_NUMBER ; break;
794 case 14:
795 case 19: nType = style::NumberingType::FULLWIDTH_ARABIC ; break;
796 case 30: nType = style::NumberingType::TIAN_GAN_ZH ; break;
797 case 31: nType = style::NumberingType::DI_ZI_ZH ; break;
798 case 35:
799 case 36:
800 case 37:
801 case 39:
802 nType = style::NumberingType::NUMBER_LOWER_ZH ; break;
803 case 34: nType = style::NumberingType::NUMBER_UPPER_ZH_TW ; break;
804 case 38: nType = style::NumberingType::NUMBER_UPPER_ZH ; break;
805 case 10:
806 case 11:
807 nType = style::NumberingType::NUMBER_TRADITIONAL_JA ; break;
808 case 20: nType = style::NumberingType::AIU_FULLWIDTH_JA ; break;
809 case 12: nType = style::NumberingType::AIU_HALFWIDTH_JA ; break;
810 case 21: nType = style::NumberingType::IROHA_FULLWIDTH_JA ; break;
811 case 13: nType = style::NumberingType::IROHA_HALFWIDTH_JA ; break;
812 case 24: nType = style::NumberingType::HANGUL_SYLLABLE_KO; break;
813 case 25: nType = style::NumberingType::HANGUL_JAMO_KO; break;
814 case 41: nType = style::NumberingType::NUMBER_HANGUL_KO; break;
815 case 44: nType = style::NumberingType::NUMBER_UPPER_KO; break;
816
817 default:
818 // take default
819 nType = style::NumberingType::ARABIC;
820 break;
821 }
822
823 // If a number level is not going to be used, then record this fact
824 if (style::NumberingType::NUMBER_NONE == nType)
825 rNotReallyThere[nLevel] = true;
826
827 /*
828 If a number level was not used (i.e. is in NotReallyThere), and that
829 number level appears at one of the positions in the display string of the
830 list, then it effectively is not there at all. So remove that level entry
831 from a copy of the aOfsNumsXCH.
832 */
833 std::vector<sal_uInt8> aOfsNumsXCH;
834 typedef std::vector<sal_uInt8>::iterator myIter;
835 aOfsNumsXCH.reserve(nMaxLevel);
836
837 for(nLevelB = 0; nLevelB < nMaxLevel; ++nLevelB)
838 aOfsNumsXCH.push_back(aLVL.aOfsNumsXCH[nLevelB]);
839
840 for(nLevelB = 0; nLevelB <= nLevel; ++nLevelB)
841 {
842 sal_uInt8 nPos = aOfsNumsXCH[nLevelB];
843 if (nPos && sNumString.GetChar(nPos-1) < nMaxLevel)
844 {
845 if (rNotReallyThere[nLevelB])
846 aOfsNumsXCH[nLevelB] = 0;
847 }
848 }
849 myIter aIter = std::remove(aOfsNumsXCH.begin(), aOfsNumsXCH.end(), 0);
850 myIter aEnd = aOfsNumsXCH.end();
851 // --> OD 2006-01-16 #i60633# - suppress access on <aOfsNumsXCH.end()>
852 if ( aIter != aEnd )
853 {
854 // Somehow the first removed vector element, at which <aIter>
855 // points to, isn't reset to zero.
856 // Investigation is needed to clarify why. It seems that only
857 // special arrays are handled correctly by this code.
858 ++aIter;
859 while (aIter != aEnd)
860 {
861 (*aIter) = 0;
862 ++aIter;
863 }
864 }
865 // <--
866
867 sal_uInt8 nUpperLevel = 0; // akt. Anzeigetiefe fuer den Writer
868 for(nLevelB = 0; nLevelB < nMaxLevel; ++nLevelB)
869 {
870 if (!nUpperLevel && !aOfsNumsXCH[nLevelB])
871 nUpperLevel = nLevelB;
872 }
873
874 // falls kein NULL als Terminierungs-Char kam,
875 // ist die Liste voller Indices, d.h. alle Plaetze sind besetzt,
876 // also sind alle Level anzuzeigen
877 if (!nUpperLevel)
878 nUpperLevel = nMaxLevel;
879
880 if (style::NumberingType::CHAR_SPECIAL == nType)
881 {
882 cBullet = sNumString.Len() ? sNumString.GetChar(0) : 0x2190;
883
884 if (!cBullet) // unsave control code?
885 cBullet = 0x2190;
886 } else if (style::NumberingType::BITMAP == nType) //For i120928, position index info of graphic
887 {
888 cGrfBulletCP = nWitchPicIsBullet; // This is a bullet picture ID
889 } else
890 {
891 /*
892 #83154#, #82192#, #i173#, #109158#
893 Our aOfsNumsXCH seems generally to be an array that contains the
894 offset into sNumString of locations where the numbers should be
895 filled in, so if the first "fill in a number" slot is greater than
896 1 there is a "prefix" before the number
897 */
898 //First number appears at
899 sal_uInt8 nOneBasedFirstNoIndex = aOfsNumsXCH[0];
900 xub_StrLen nFirstNoIndex =
901 nOneBasedFirstNoIndex > 0 ? nOneBasedFirstNoIndex -1 : STRING_LEN;
902 lcl_CopyGreaterEight(sPrefix, sNumString, 0, nFirstNoIndex);
903
904 //Next number appears at
905 if (nUpperLevel)
906 {
907 sal_uInt8 nOneBasedNextNoIndex = aOfsNumsXCH[nUpperLevel-1];
908 xub_StrLen nNextNoIndex =
909 nOneBasedNextNoIndex > 0 ? nOneBasedNextNoIndex -1 : STRING_LEN;
910 if (nNextNoIndex != STRING_LEN)
911 ++nNextNoIndex;
912 if (sNumString.Len() > nNextNoIndex)
913 lcl_CopyGreaterEight(sPostfix, sNumString, nNextNoIndex);
914 }
915
916 /*
917 We use lcl_CopyGreaterEight because once if we have removed unused
918 number indexes from the aOfsNumsXCH then placeholders remain in
919 sNumString which must not be copied into the final numbering strings
920 */
921 }
922
923 switch( aLVL.nAlign )
924 {
925 case 0:
926 eAdj = SVX_ADJUST_LEFT;
927 break;
928 case 1:
929 eAdj = SVX_ADJUST_CENTER;
930 break;
931 case 2:
932 eAdj = SVX_ADJUST_RIGHT;
933 break;
934 case 3:
935 // Writer here cannot do block justification
936 eAdj = SVX_ADJUST_LEFT;
937 break;
938 default:
939 // undefined value
940 ASSERT( sal_False, "Value of aLVL.nAlign is not supported" );
941 // take default
942 eAdj = SVX_ADJUST_LEFT;
943 break;
944 }
945
946 // 6. entsprechendes NumFmt konfigurieren
947 if( bSetStartNo )
948 rNumFmt.SetStart( nStartNo );
949 rNumFmt.SetNumberingType( nType );
950 rNumFmt.SetNumAdjust( eAdj );
951
952 if( style::NumberingType::CHAR_SPECIAL == nType )
953 {
954 // first character of the Prefix-Text is the Bullet
955 rNumFmt.SetBulletChar(cBullet);
956 // Don't forget: unten, nach dem Bauen eventueller Styles auch noch
957 // SetBulletFont() rufen !!!
958 }
959 //For i120928,position index info
960 else if (style::NumberingType::BITMAP == nType)
961 {
962 rNumFmt.SetGrfBulletCP(cGrfBulletCP);
963 }
964 else
965 {
966 // reminder: Garnix ist default Prefix
967 if( sPrefix.Len() )
968 rNumFmt.SetPrefix( sPrefix );
969 // reminder: Point is default Postfix
970 rNumFmt.SetSuffix( sPostfix );
971 rNumFmt.SetIncludeUpperLevels( nUpperLevel );
972 }
973
974 // --> OD 2008-06-04 #i89181#
975 if ( rNumFmt.GetPositionAndSpaceMode() ==
976 SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
977 {
978 if (eAdj == SVX_ADJUST_RIGHT)
979 {
980 rNumFmt.SetAbsLSpace(aLVL.nDxaLeft);
981 rNumFmt.SetFirstLineOffset(-aLVL.nDxaLeft);
982 rNumFmt.SetCharTextDistance(-aLVL.nDxaLeft1);
983 }
984 else
985 {
986 rNumFmt.SetAbsLSpace( aLVL.nDxaLeft );
987 rNumFmt.SetFirstLineOffset(aLVL.nDxaLeft1);
988 }
989 }
990 else
991 {
992 rNumFmt.SetIndentAt( aLVL.nDxaLeft );
993 rNumFmt.SetFirstLineIndent(aLVL.nDxaLeft1);
994 rNumFmt.SetListtabPos( nTabPos );
995 SvxNumberFormat::SvxNumLabelFollowedBy eNumLabelFollowedBy = SvxNumberFormat::LISTTAB;
996 switch ( ixchFollow )
997 {
998 case 0:
999 {
1000 eNumLabelFollowedBy = SvxNumberFormat::LISTTAB;
1001 }
1002 break;
1003 case 1:
1004 {
1005 eNumLabelFollowedBy = SvxNumberFormat::SPACE;
1006 }
1007 break;
1008 case 2:
1009 {
1010 eNumLabelFollowedBy = SvxNumberFormat::NOTHING;
1011 }
1012 break;
1013 }
1014 rNumFmt.SetLabelFollowedBy( eNumLabelFollowedBy );
1015 }
1016
1017 return true;
1018 }
1019
AdjustLVL(sal_uInt8 nLevel,SwNumRule & rNumRule,WW8aISet & rListItemSet,WW8aCFmt & rCharFmt,bool & bNewCharFmtCreated,String sPrefix)1020 void WW8ListManager::AdjustLVL( sal_uInt8 nLevel, SwNumRule& rNumRule,
1021 WW8aISet& rListItemSet, WW8aCFmt& rCharFmt, bool& bNewCharFmtCreated,
1022 String sPrefix )
1023 {
1024 bNewCharFmtCreated = false;
1025 SfxItemSet* pThisLevelItemSet;
1026 SfxItemSet* pLowerLevelItemSet;
1027 sal_uInt8 nIdenticalItemSetLevel;
1028 const SfxPoolItem* pItem;
1029
1030 SwNumFmt aNumFmt = rNumRule.Get( nLevel );
1031
1032 pThisLevelItemSet = rListItemSet[ nLevel ];
1033
1034 if( pThisLevelItemSet && pThisLevelItemSet->Count())
1035 {
1036 nIdenticalItemSetLevel = nMaxLevel;
1037 SfxItemIter aIter( *pThisLevelItemSet );
1038 for (sal_uInt8 nLowerLevel = 0; nLowerLevel < nLevel; ++nLowerLevel)
1039 {
1040 pLowerLevelItemSet = rListItemSet[ nLowerLevel ];
1041 if( pLowerLevelItemSet
1042 && (pLowerLevelItemSet->Count() == pThisLevelItemSet->Count()) )
1043 {
1044 nIdenticalItemSetLevel = nLowerLevel;
1045 sal_uInt16 nWhich = aIter.GetCurItem()->Which();
1046 while (true)
1047 {
1048 if( // ggfs. passenden pItem im pLowerLevelItemSet finden
1049 (SFX_ITEM_SET != pLowerLevelItemSet->GetItemState(
1050 nWhich, false, &pItem ) )
1051 || // virtuellen "!=" Operator anwenden
1052 (*pItem != *aIter.GetCurItem() ) )
1053 // falls kein Item mit gleicher nWhich gefunden oder Werte
1054 // der Items ungleich, Ungleichheit merken und abbrechen!
1055 {
1056 nIdenticalItemSetLevel = nMaxLevel;
1057 break;
1058 }
1059 if( aIter.IsAtEnd() )
1060 break;
1061 nWhich = aIter.NextItem()->Which();
1062 }
1063
1064 if( nIdenticalItemSetLevel != nMaxLevel )
1065 break;
1066 }
1067 }
1068
1069 SwCharFmt* pFmt;
1070 if (nMaxLevel == nIdenticalItemSetLevel)
1071 {
1072 // Style definieren
1073 String aName( sPrefix.Len() ? sPrefix : rNumRule.GetName() );
1074 (aName += 'z') += String::CreateFromInt32( nLevel );
1075
1076 // const Wegcasten
1077 pFmt = rDoc.MakeCharFmt(aName, (SwCharFmt*)rDoc.GetDfltCharFmt());
1078 bNewCharFmtCreated = true;
1079 // Attribute reinsetzen
1080 pFmt->SetFmtAttr( *pThisLevelItemSet );
1081 }
1082 else
1083 {
1084 // passenden Style hier anhaengen
1085 pFmt = rCharFmt[ nIdenticalItemSetLevel ];
1086 }
1087
1088 // merken
1089 rCharFmt[ nLevel ] = pFmt;
1090
1091 //
1092 // Style an das NumFormat haengen
1093 //
1094 aNumFmt.SetCharFmt( pFmt );
1095 }
1096 //Modify for #119405 by chengjh, 2012-08-16
1097 //Ensure the default char fmt is initialized for any level of num ruler if no customized attr
1098 else
1099 {
1100 SwCharFmt* pFmt = aNumFmt.GetCharFmt();
1101 if ( !pFmt)
1102 {
1103 String aName( sPrefix.Len() ? sPrefix : rNumRule.GetName() );
1104 (aName += 'z') += String::CreateFromInt32( nLevel );
1105
1106 pFmt = rDoc.MakeCharFmt(aName, (SwCharFmt*)rDoc.GetDfltCharFmt());
1107 bNewCharFmtCreated = true;
1108 rCharFmt[ nLevel ] = pFmt;
1109 aNumFmt.SetCharFmt( pFmt );
1110 }
1111 }
1112 //End
1113 //
1114 // ggfs. Bullet Font an das NumFormat haengen
1115 //
1116 if( SVX_NUM_CHAR_SPECIAL == aNumFmt.GetNumberingType() )
1117 {
1118 SwCharFmt* pFmt = aNumFmt.GetCharFmt();
1119 Font aFont;
1120 if( !pFmt )
1121 {
1122 // --> OD 2006-06-27 #b6440955#
1123 // aFont = SwNumRule::GetDefBulletFont();
1124 aFont = numfunc::GetDefBulletFont();
1125 // <--
1126 }
1127 else
1128 {
1129 const SvxFontItem& rFontItem = pFmt->GetFont();
1130 aFont.SetFamily( rFontItem.GetFamily() );
1131 aFont.SetName( rFontItem.GetFamilyName() );
1132 aFont.SetStyleName( rFontItem.GetStyleName() );
1133 aFont.SetPitch( rFontItem.GetPitch() );
1134 aFont.SetCharSet( rFontItem.GetCharSet() );
1135 }
1136 aNumFmt.SetBulletFont( &aFont );
1137 }
1138 //
1139 // und wieder rein in die NumRule
1140 //
1141 rNumRule.Set(nLevel, aNumFmt);
1142 }
1143
CreateNextRule(bool bSimple)1144 SwNumRule* WW8ListManager::CreateNextRule(bool bSimple)
1145 {
1146 // wird erstmal zur Bildung des Style Namens genommen
1147 String sPrefix(CREATE_CONST_ASC("WW8Num"));
1148 sPrefix += String::CreateFromInt32(nUniqueList++);
1149 // --> OD 2008-06-04 #i86652#
1150 // sal_uInt16 nRul = rDoc.MakeNumRule(rDoc.GetUniqueNumRuleName(&sPrefix));
1151 sal_uInt16 nRul =
1152 rDoc.MakeNumRule( rDoc.GetUniqueNumRuleName(&sPrefix), 0, sal_False,
1153 SvxNumberFormat::LABEL_ALIGNMENT );
1154 // <--
1155 SwNumRule* pMyNumRule = rDoc.GetNumRuleTbl()[nRul];
1156 pMyNumRule->SetAutoRule(false);
1157 pMyNumRule->SetContinusNum(bSimple);
1158 return pMyNumRule;
1159 }
1160
GetNumRule(sal_uInt16 i)1161 SwNumRule* WW8ListManager::GetNumRule(sal_uInt16 i)
1162 {
1163 if ( i < maLSTInfos.size() )
1164 return maLSTInfos[i]->pNumRule;
1165 else
1166 return 0;
1167 }
1168
1169 // oeffentliche Methoden /////////////////////////////////////////////////////
1170 //
WW8ListManager(SvStream & rSt_,SwWW8ImplReader & rReader_)1171 WW8ListManager::WW8ListManager(
1172 SvStream& rSt_,
1173 SwWW8ImplReader& rReader_ )
1174 : maSprmParser( rReader_.GetFib().GetFIBVersion() )
1175 , rReader(rReader_)
1176 , rDoc(rReader.GetDoc())
1177 , rFib(rReader.GetFib())
1178 , rSt(rSt_)
1179 , maLSTInfos()
1180 , pLFOInfos( NULL )
1181 , nUniqueList( 1 )
1182 , maStyleInList()
1183 {
1184 // LST und LFO gibts erst ab WW8
1185 if( ( 8 > rFib.nVersion )
1186 || ( rFib.fcPlcfLst == rFib.fcPlfLfo )
1187 || ( !rFib.lcbPlcfLst )
1188 || ( !rFib.lcbPlfLfo ) ) return; // offensichtlich keine Listen da
1189
1190 // Arrays anlegen
1191 pLFOInfos = new WW8LFOInfos;
1192 bool bLVLOk = true;
1193 sal_uInt8 aBits1;
1194
1195 nLastLFOPosition = USHRT_MAX;
1196 long nOriginalPos = rSt.Tell();
1197 //
1198 // 1. PLCF LST auslesen und die Listen Vorlagen im Writer anlegen
1199 //
1200 rSt.Seek( rFib.fcPlcfLst );
1201 sal_uInt16 nListCount;
1202 rSt >> nListCount;
1203 bool bOk = 0 < nListCount;
1204 if( bOk )
1205 {
1206 WW8LST aLST;
1207 //
1208 // 1.1 alle LST einlesen
1209 //
1210 for (sal_uInt16 nList=0; nList < nListCount; ++nList)
1211 {
1212 bOk = false;
1213 memset(&aLST, 0, sizeof( aLST ));
1214 sal_uInt16 nLevel;
1215 //
1216 // 1.1.1 Daten einlesen
1217 //
1218 rSt >> aLST.nIdLst;
1219 rSt >> aLST.nTplC;
1220 for (nLevel = 0; nLevel < nMaxLevel; ++nLevel)
1221 rSt >> aLST.aIdSty[ nLevel ];
1222
1223
1224 rSt >> aBits1;
1225
1226 rSt.SeekRel( 1 );
1227
1228 if (rSt.GetError())
1229 break;
1230
1231 if( aBits1 & 0x01 )
1232 aLST.bSimpleList = true;
1233 if( aBits1 & 0x02 )
1234 aLST.bRestartHdn = true;
1235
1236 // 1.1.2 new NumRule inserted in Doc and WW8LSTInfo marked
1237
1238 /*
1239 #i1869#
1240 In Word 2000 Microsoft got rid of creating new "simple lists" with
1241 only 1 level, all new lists are created with 9 levels. To hack it
1242 so that the list types formerly known as simple lists still have
1243 their own tab page to themselves one of the reserved bits is used
1244 to show that a given list is to be in the simple list tabpage.
1245 This has now nothing to do with the actual number of list level a
1246 list has, only how many will be shown in the user interface.
1247
1248 i.e. create a simple list in 2000 and open it in 97 and 97 will
1249 claim (correctly) that it is an outline list. We can set our
1250 continuous flag in these lists to store this information.
1251 */
1252 SwNumRule* pMyNumRule = CreateNextRule(
1253 aLST.bSimpleList || (aBits1 & 0x10));
1254
1255 WW8LSTInfo* pLSTInfo = new WW8LSTInfo(pMyNumRule, aLST);
1256 maLSTInfos.push_back(pLSTInfo);
1257 bOk = true;
1258 }
1259 }
1260
1261 if( bOk )
1262 {
1263 //
1264 // 1.2 alle LVL aller aLST einlesen
1265 //
1266 sal_uInt8 nLevel;
1267 sal_uInt16 nLSTInfos = static_cast< sal_uInt16 >(maLSTInfos.size());
1268 for (sal_uInt16 nList = 0; nList < nLSTInfos; ++nList)
1269 {
1270 bOk = false;
1271 WW8LSTInfo* pListInfo = maLSTInfos[nList];
1272 if( !pListInfo || !pListInfo->pNumRule ) break;
1273 SwNumRule& rMyNumRule = *pListInfo->pNumRule;
1274 //
1275 // 1.2.1 betreffende(n) LVL(s) fuer diese aLST einlesen
1276 //
1277 sal_uInt16 nLvlCount = static_cast< sal_uInt16 >(pListInfo->bSimpleList ? nMinLevel : nMaxLevel);
1278 std::deque<bool> aNotReallyThere;
1279 aNotReallyThere.resize(nMaxLevel);
1280 pListInfo->maParaSprms.resize(nMaxLevel);
1281 for (nLevel = 0; nLevel < nLvlCount; ++nLevel)
1282 {
1283 SwNumFmt aNumFmt( rMyNumRule.Get( nLevel ) );
1284 // LVLF einlesen
1285 bLVLOk = ReadLVL( aNumFmt, pListInfo->aItemSet[nLevel],
1286 pListInfo->aIdSty[nLevel], true, aNotReallyThere, nLevel,
1287 pListInfo->maParaSprms[nLevel]);
1288 if( !bLVLOk )
1289 break;
1290 // und in die rMyNumRule aufnehmen
1291 rMyNumRule.Set( nLevel, aNumFmt );
1292 }
1293 if( !bLVLOk )
1294 break;
1295 //
1296 // 1.2.2 die ItemPools mit den CHPx Einstellungen der verschiedenen
1297 // Level miteinander vergleichen und ggfs. Style(s) erzeugen
1298 //
1299 bool bDummy;
1300 for (nLevel = 0; nLevel < nLvlCount; ++nLevel)
1301 {
1302 AdjustLVL( nLevel, rMyNumRule, pListInfo->aItemSet,
1303 pListInfo->aCharFmt, bDummy );
1304 }
1305 //
1306 // 1.2.3 ItemPools leeren und loeschen
1307 //
1308 for (nLevel = 0; nLevel < nLvlCount; ++nLevel)
1309 delete pListInfo->aItemSet[ nLevel ];
1310 bOk = true;
1311 }
1312 }
1313 if( !bOk )
1314 {
1315 // Fehler aufgetreten - LSTInfos abraeumen !!!
1316
1317 ;
1318 }
1319
1320 //
1321 // 2. PLF LFO auslesen und speichern
1322 //
1323 long nLfoCount(0);
1324 if (bOk)
1325 {
1326 rSt.Seek(rFib.fcPlfLfo);
1327 rSt >> nLfoCount;
1328 if (0 >= nLfoCount)
1329 bOk = false;
1330 }
1331
1332 if(bOk)
1333 {
1334 WW8LFO aLFO;
1335 //
1336 // 2.1 alle LFO einlesen
1337 //
1338 for (sal_uInt16 nLfo = 0; nLfo < nLfoCount; ++nLfo)
1339 {
1340 bOk = false;
1341 memset(&aLFO, 0, sizeof( aLFO ));
1342 rSt >> aLFO.nIdLst;
1343 rSt.SeekRel( 8 );
1344 rSt >> aLFO.nLfoLvl;
1345 rSt.SeekRel( 3 );
1346 // soviele Overrides existieren
1347 if ((nMaxLevel < aLFO.nLfoLvl) || rSt.GetError())
1348 break;
1349
1350 // die Parent NumRule der entsprechenden Liste ermitteln
1351 WW8LSTInfo* pParentListInfo = GetLSTByListId(aLFO.nIdLst);
1352 if (pParentListInfo)
1353 {
1354 // hier, im ersten Schritt, erst mal diese NumRule festhalten
1355 aLFO.pNumRule = pParentListInfo->pNumRule;
1356
1357 // hat die Liste mehrere Level ?
1358 aLFO.bSimpleList = pParentListInfo->bSimpleList;
1359 }
1360 // und rein ins Merk-Array mit dem Teil
1361 WW8LFOInfo* pLFOInfo = new WW8LFOInfo(aLFO);
1362 if ( pParentListInfo != NULL )
1363 {
1364 // Copy the basic paragraph properties for each level from the
1365 // original list into the list format override levels.
1366 int nMaxSize = pParentListInfo->maParaSprms.size();
1367 pLFOInfo->maParaSprms.resize(nMaxSize);
1368 for (int i = 0; i < nMaxSize; ++i)
1369 {
1370 pLFOInfo->maParaSprms[i] = pParentListInfo->maParaSprms[i];
1371 }
1372
1373 const sal_uInt16 nLFOInfoArrayPos = pLFOInfos->Count();
1374 for ( sal_uInt8 j = 0 ; j < nMaxLevel; ++j )
1375 {
1376 maStyleInList[pParentListInfo->aIdSty[j]] = nLFOInfoArrayPos;
1377 }
1378 }
1379 pLFOInfos->Insert( pLFOInfo, pLFOInfos->Count() );
1380 bOk = true;
1381 }
1382 }
1383 if( bOk )
1384 {
1385 //
1386 // 2.2 fuer alle LFO die zugehoerigen LFOLVL einlesen
1387 //
1388 sal_uInt16 nLFOInfos = pLFOInfos ? pLFOInfos->Count() : 0;
1389 for (sal_uInt16 nLfo = 0; nLfo < nLFOInfos; ++nLfo)
1390 {
1391 bOk = false;
1392 WW8LFOInfo* pLFOInfo = pLFOInfos->GetObject( nLfo );
1393 if (!pLFOInfo)
1394 break;
1395 // stehen hierfuer ueberhaupt LFOLVL an ?
1396 if( pLFOInfo->bOverride )
1397 {
1398 WW8LSTInfo* pParentListInfo = GetLSTByListId(pLFOInfo->nIdLst);
1399 if (!pParentListInfo) //e.g. #112324#
1400 break;
1401 //
1402 // 2.2.1 eine neue NumRule fuer diese Liste anlegen
1403 //
1404 SwNumRule* pParentNumRule = pLFOInfo->pNumRule;
1405 ASSERT(pParentNumRule, "ww: Impossible lists, please report");
1406 if( !pParentNumRule )
1407 break;
1408 // Nauemsprefix aufbauen: fuer NumRule-Name (eventuell)
1409 // und (falls vorhanden) fuer Style-Name (dann auf jeden Fall)
1410 String sPrefix(CREATE_CONST_ASC( "WW8NumSt" ));
1411 sPrefix += String::CreateFromInt32( nLfo + 1 );
1412 // jetzt dem pNumRule seinen RICHTIGEN Wert zuweisen !!!
1413 // (bis dahin war hier die Parent NumRule vermerkt )
1414 //
1415 // Dazu erst mal nachsehen, ob ein Style diesen LFO
1416 // referenziert:
1417 if( USHRT_MAX > rReader.StyleUsingLFO( nLfo ) )
1418 {
1419 sal_uInt16 nRul = rDoc.MakeNumRule(
1420 rDoc.GetUniqueNumRuleName( &sPrefix ), pParentNumRule);
1421 pLFOInfo->pNumRule = rDoc.GetNumRuleTbl()[ nRul ];
1422 pLFOInfo->pNumRule->SetAutoRule(false);
1423 }
1424 else
1425 {
1426 sal_uInt16 nRul = rDoc.MakeNumRule(
1427 rDoc.GetUniqueNumRuleName(), pParentNumRule);
1428 pLFOInfo->pNumRule = rDoc.GetNumRuleTbl()[ nRul ];
1429 pLFOInfo->pNumRule->SetAutoRule(true); // = default
1430 }
1431 //
1432 // 2.2.2 alle LFOLVL (und ggfs. LVL) fuer die neue NumRule
1433 // einlesen
1434 //
1435 WW8aISet aItemSet; // Zeichenattribute aus GrpprlChpx
1436 WW8aCFmt aCharFmt; // Zeichen Style Pointer
1437 memset(&aItemSet, 0, sizeof( aItemSet ));
1438 memset(&aCharFmt, 0, sizeof( aCharFmt ));
1439
1440 //2.2.2.0 skip inter-group of override header ?
1441 //See #i25438# for why I moved this here, compare
1442 //that original bugdoc's binary to what it looks like
1443 //when resaved with Word, i.e. there is always a
1444 //4 byte header, there might be more than one if
1445 //that header was 0xFFFFFFFF, e.g. #114412# ?
1446 sal_uInt32 nTest;
1447 rSt >> nTest;
1448 do
1449 rSt >> nTest;
1450 while (nTest == 0xFFFFFFFF);
1451 rSt.SeekRel(-4);
1452
1453 std::deque<bool> aNotReallyThere(WW8ListManager::nMaxLevel);
1454 sal_uInt8 nLevel = 0;
1455 for (nLevel = 0; nLevel < pLFOInfo->nLfoLvl; ++nLevel)
1456 {
1457 WW8LFOLVL aLFOLVL;
1458 bLVLOk = false;
1459
1460 //
1461 // 2.2.2.1 den LFOLVL einlesen
1462 //
1463 rSt >> aLFOLVL.nStartAt;
1464 rSt >> aBits1;
1465 rSt.SeekRel( 3 );
1466 if (rSt.GetError())
1467 break;
1468
1469 // beachte: Die Witzbolde bei MS quetschen die
1470 // Override-Level-Nummer in vier Bits hinein, damit sie
1471 // wieder einen Grund haben, ihr Dateiformat zu aendern,
1472 // falls ihnen einfaellt, dass sie eigentlich doch gerne
1473 // bis zu 16 Listen-Level haetten. Wir tun das *nicht*
1474 // (siehe Kommentar oben bei "struct
1475 // WW8LFOInfo")
1476 aLFOLVL.nLevel = aBits1 & 0x0F;
1477 if( (0xFF > aBits1) &&
1478 (nMaxLevel > aLFOLVL.nLevel) )
1479 {
1480 if (aBits1 & 0x10)
1481 aLFOLVL.bStartAt = true;
1482 else
1483 aLFOLVL.bStartAt = false;
1484 //
1485 // 2.2.2.2 eventuell auch den zugehoerigen LVL einlesen
1486 //
1487 SwNumFmt aNumFmt(
1488 pLFOInfo->pNumRule->Get(aLFOLVL.nLevel));
1489 if (aBits1 & 0x20)
1490 {
1491 aLFOLVL.bFormat = true;
1492 // falls bStartup true, hier den Startup-Level
1493 // durch den im LVL vermerkten ersetzen LVLF
1494 // einlesen
1495 bLVLOk = ReadLVL(aNumFmt, aItemSet[nLevel],
1496 pParentListInfo->aIdSty[nLevel],
1497 aLFOLVL.bStartAt, aNotReallyThere, nLevel,
1498 pLFOInfo->maParaSprms[nLevel]);
1499
1500 if (!bLVLOk)
1501 break;
1502 }
1503 else if (aLFOLVL.bStartAt)
1504 {
1505 aNumFmt.SetStart(
1506 writer_cast<sal_uInt16>(aLFOLVL.nStartAt));
1507 }
1508 //
1509 // 2.2.2.3 das NumFmt in die NumRule aufnehmen
1510 //
1511 pLFOInfo->pNumRule->Set(aLFOLVL.nLevel, aNumFmt);
1512 }
1513 bLVLOk = true;
1514
1515 if (nMaxLevel > aLFOLVL.nLevel)
1516 pLFOInfo->maOverrides[aLFOLVL.nLevel] = aLFOLVL;
1517 }
1518 if( !bLVLOk )
1519 break;
1520 //
1521 // 2.2.3 die LVL der neuen NumRule anpassen
1522 //
1523 sal_uInt16 aFlagsNewCharFmt = 0;
1524 bool bNewCharFmtCreated = false;
1525 for (nLevel = 0; nLevel < pLFOInfo->nLfoLvl; ++nLevel)
1526 {
1527 AdjustLVL( nLevel, *pLFOInfo->pNumRule, aItemSet, aCharFmt,
1528 bNewCharFmtCreated, sPrefix );
1529 if( bNewCharFmtCreated )
1530 aFlagsNewCharFmt += (1 << nLevel);
1531 }
1532 //
1533 // 2.2.4 ItemPools leeren und loeschen
1534 //
1535 for (nLevel = 0; nLevel < pLFOInfo->nLfoLvl; ++nLevel)
1536 delete aItemSet[ nLevel ];
1537 bOk = true;
1538 }
1539 }
1540 }
1541 if( !bOk )
1542 {
1543 // Fehler aufgetreten - LSTInfos und LFOInfos abraeumen !!!
1544 ;
1545 }
1546 // und schon sind wir fertig!
1547 rSt.Seek( nOriginalPos );
1548 }
1549
~WW8ListManager()1550 WW8ListManager::~WW8ListManager()
1551 {
1552 /*
1553 named lists remain in doc!!!
1554 unnamed lists are deleted when unused
1555 pLFOInfos are in any case destructed
1556 */
1557 for(std::vector<WW8LSTInfo *>::iterator aIter = maLSTInfos.begin();
1558 aIter != maLSTInfos.end(); ++aIter)
1559 {
1560 if ((*aIter)->pNumRule && !(*aIter)->bUsedInDoc &&
1561 (*aIter)->pNumRule->IsAutoRule())
1562 {
1563 rDoc.DelNumRule((*aIter)->pNumRule->GetName());
1564 }
1565 delete *aIter;
1566 }
1567
1568 if (pLFOInfos)
1569 {
1570 for(sal_uInt16 nInfo = pLFOInfos->Count(); nInfo; )
1571 {
1572 WW8LFOInfo *pActInfo = pLFOInfos->GetObject(--nInfo);
1573 if (pActInfo->bOverride && pActInfo->pNumRule
1574 && !pActInfo->bUsedInDoc && pActInfo->pNumRule->IsAutoRule())
1575 {
1576 rDoc.DelNumRule( pActInfo->pNumRule->GetName() );
1577 }
1578 }
1579 delete pLFOInfos;
1580 }
1581 }
1582
GetPossibleLFOPosition(const sal_uInt16 nStyleID,const sal_uInt8 nGivenListLevel)1583 sal_uInt16 WW8ListManager::GetPossibleLFOPosition(
1584 const sal_uInt16 nStyleID,
1585 const sal_uInt8 nGivenListLevel )
1586 {
1587 sal_uInt16 nPossibleLFOPosition = USHRT_MAX;
1588
1589 StyleInList::iterator aItr = maStyleInList.find( nStyleID );
1590 if ( aItr != maStyleInList.end()
1591 && aItr->second < pLFOInfos->Count() )
1592 {
1593 WW8LFOInfo* pLFOInfo = pLFOInfos->GetObject( aItr->second );
1594 WW8LSTInfo* pParentListInfo = GetLSTByListId( pLFOInfo->nIdLst );
1595 if ( pParentListInfo != NULL
1596 && pParentListInfo->aIdSty[nGivenListLevel] == nStyleID )
1597 {
1598 nPossibleLFOPosition = aItr->second;
1599 }
1600 }
1601
1602 return nPossibleLFOPosition;
1603 }
1604
1605
IsEqualFormatting(const SwNumRule & rOne,const SwNumRule & rTwo)1606 bool IsEqualFormatting(const SwNumRule &rOne, const SwNumRule &rTwo)
1607 {
1608 bool bRet =
1609 (
1610 rOne.GetRuleType() == rTwo.GetRuleType() &&
1611 rOne.IsContinusNum() == rTwo.IsContinusNum() &&
1612 rOne.IsAbsSpaces() == rTwo.IsAbsSpaces() &&
1613 rOne.GetPoolFmtId() == rTwo.GetPoolFmtId() &&
1614 rOne.GetPoolHelpId() == rTwo.GetPoolHelpId() &&
1615 rTwo.GetPoolHlpFileId() == rTwo.GetPoolHlpFileId()
1616 );
1617
1618 if (bRet)
1619 {
1620 for (sal_uInt8 n = 0; n < MAXLEVEL; ++n )
1621 {
1622 // The SvxNumberFormat compare, not the SwNumFmt compare
1623 const SvxNumberFormat &rO = rOne.Get(n);
1624 const SvxNumberFormat &rT = rTwo.Get(n);
1625 if (!(rO == rT))
1626 {
1627 bRet = false;
1628 break;
1629 }
1630 }
1631 }
1632 return bRet;
1633 }
1634
GetNumRuleForActivation(sal_uInt16 nLFOPosition,const sal_uInt8 nLevel,std::vector<sal_uInt8> & rParaSprms,SwTxtNode * pNode)1635 SwNumRule* WW8ListManager::GetNumRuleForActivation(sal_uInt16 nLFOPosition,
1636 const sal_uInt8 nLevel, std::vector<sal_uInt8> &rParaSprms, SwTxtNode *pNode)
1637 {
1638 sal_uInt16 nLFOInfos = pLFOInfos ? pLFOInfos->Count() : 0;
1639 if( nLFOInfos <= nLFOPosition )
1640 return 0;
1641
1642 WW8LFOInfo* pLFOInfo = pLFOInfos->GetObject( nLFOPosition );
1643
1644 if( !pLFOInfo )
1645 return 0;
1646
1647 bool bFirstUse = !pLFOInfo->bUsedInDoc;
1648 pLFOInfo->bUsedInDoc = true;
1649
1650 if( !pLFOInfo->pNumRule )
1651 return 0;
1652
1653 // #i25545#
1654 // --> OD 2009-03-12 #i100132# - a number format does not have to exist on given list level
1655 // SwNumFmt pFmt(*(pLFOInfo->pNumRule->GetNumFmt(nLevel)));
1656 SwNumFmt pFmt(pLFOInfo->pNumRule->Get(nLevel));
1657 // <--
1658 if (rReader.IsRightToLeft() && nLastLFOPosition != nLFOPosition) {
1659 if ( pFmt.GetNumAdjust() == SVX_ADJUST_RIGHT)
1660 pFmt.SetNumAdjust(SVX_ADJUST_LEFT);
1661 else if ( pFmt.GetNumAdjust() == SVX_ADJUST_LEFT)
1662 pFmt.SetNumAdjust(SVX_ADJUST_RIGHT);
1663 pLFOInfo->pNumRule->Set(nLevel, pFmt);
1664 }
1665 nLastLFOPosition = nLFOPosition;
1666 /*
1667 #i1869#
1668 If this list has had its bits set in Word 2000 to pretend that it is a
1669 simple list from the point of view of the user, then it is almost
1670 certainly a simple continuous list, and we will try to keep it like that.
1671 Otherwise when we save again it will be shown as the true outline list
1672 that it is, confusing the user that just wanted what they thought was a
1673 simple list. On the other hand it is possible that some of the other levels
1674 were used by the user, in which case we will not pretend anymore that it
1675 is a simple list. Something that Word 2000 does anyway, that 97 didn't, to
1676 my bewilderment.
1677 */
1678 if (nLevel && pLFOInfo->pNumRule->IsContinusNum())
1679 pLFOInfo->pNumRule->SetContinusNum(false);
1680
1681 if( (!pLFOInfo->bOverride) && (!pLFOInfo->bLSTbUIDSet) )
1682 {
1683 WW8LSTInfo* pParentListInfo = GetLSTByListId( pLFOInfo->nIdLst );
1684 if( pParentListInfo )
1685 pParentListInfo->bUsedInDoc = true;
1686 pLFOInfo->bLSTbUIDSet = true;
1687 }
1688
1689 if (pLFOInfo->maParaSprms.size() > nLevel)
1690 rParaSprms = pLFOInfo->maParaSprms[nLevel];
1691
1692 SwNumRule *pRet = pLFOInfo->pNumRule;
1693
1694 bool bRestart(false);
1695 sal_uInt16 nStart(0);
1696 bool bNewstart(false);
1697 /*
1698 Note: If you fiddle with this then you have to make sure that #i18322#
1699 #i13833#, #i20095# and #112466# continue to work
1700
1701 Check if there were overrides for this level
1702 */
1703 if (pLFOInfo->bOverride && nLevel < pLFOInfo->nLfoLvl)
1704 {
1705 WW8LSTInfo* pParentListInfo = GetLSTByListId(pLFOInfo->nIdLst);
1706 ASSERT(pParentListInfo, "ww: Impossible lists, please report");
1707 if (pParentListInfo && pParentListInfo->pNumRule)
1708 {
1709 const WW8LFOLVL &rOverride = pLFOInfo->maOverrides[nLevel];
1710 bool bNoChangeFromParent =
1711 IsEqualFormatting(*pRet, *(pParentListInfo->pNumRule));
1712
1713 // If so then I think Word still uses the parent (maybe)
1714 if (bNoChangeFromParent)
1715 {
1716 pRet = pParentListInfo->pNumRule;
1717
1718 //did it not affect start at value ?
1719 if (bFirstUse)
1720 {
1721 if (rOverride.bStartAt)
1722 {
1723 const SwNumFmt &rFmt =
1724 pParentListInfo->pNumRule->Get(nLevel);
1725 if (
1726 rFmt.GetStart() ==
1727 pLFOInfo->maOverrides[nLevel].nStartAt
1728 )
1729 {
1730 bRestart = true;
1731 }
1732 else
1733 {
1734 bNewstart = true;
1735 nStart = writer_cast<sal_uInt16>
1736 (pLFOInfo->maOverrides[nLevel].nStartAt);
1737 }
1738 }
1739 }
1740
1741 pParentListInfo->bUsedInDoc = true;
1742 }
1743 }
1744 }
1745
1746 if (pNode)
1747 {
1748 pNode->SetAttrListLevel(nLevel);
1749
1750 if (bRestart || bNewstart) // #112466# (I think)
1751 pNode->SetListRestart(true);
1752 if (bNewstart)
1753 pNode->SetAttrListRestartValue(nStart);
1754 }
1755 return pRet;
1756 }
1757
1758
1759 //----------------------------------------------------------------------------
1760 // SwWW8ImplReader: anhaengen einer Liste an einen Style oder Absatz
1761 //----------------------------------------------------------------------------
SetTxtFmtCollAndListLevel(const SwPaM & rRg,SwWW8StyInf & rStyleInfo)1762 bool SwWW8ImplReader::SetTxtFmtCollAndListLevel(
1763 const SwPaM& rRg,
1764 SwWW8StyInf& rStyleInfo)
1765 {
1766 bool bRes = true;
1767 if( rStyleInfo.pFmt && rStyleInfo.bColl )
1768 {
1769 bRes = rDoc.SetTxtFmtColl(rRg, (SwTxtFmtColl*)rStyleInfo.pFmt) ? true : false;
1770 SwTxtNode* pTxtNode = pPaM->GetNode()->GetTxtNode();
1771 ASSERT( pTxtNode != NULL, "No Text-Node at PaM-Position" );
1772 if ( pTxtNode == NULL )
1773 {
1774 // make code robust
1775 return bRes;
1776 }
1777
1778 const SwNumRule * pNumRule = pTxtNode->GetNumRule(); // #i27610#
1779
1780 if( !IsInvalidOrToBeMergedTabCell()
1781 && ! (pNumRule && pNumRule->IsOutlineRule()) ) // #i27610#
1782 {
1783 pTxtNode->ResetAttr( RES_PARATR_NUMRULE );
1784 }
1785
1786 if ( USHRT_MAX > rStyleInfo.nLFOIndex
1787 && WW8ListManager::nMaxLevel > rStyleInfo.nListLevel )
1788 {
1789 const bool bApplyListStyle = false;
1790 RegisterNumFmtOnTxtNode( rStyleInfo.nLFOIndex, rStyleInfo.nListLevel, bApplyListStyle );
1791 }
1792 }
1793 return bRes;
1794 }
1795
UseListIndent(SwWW8StyInf & rStyle,const SwNumFmt & rFmt)1796 void UseListIndent(SwWW8StyInf &rStyle, const SwNumFmt &rFmt)
1797 {
1798 if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1799 {
1800 const long nAbsLSpace = rFmt.GetAbsLSpace();
1801 const long nListFirstLineIndent = GetListFirstLineIndent(rFmt);
1802 SvxLRSpaceItem aLR(ItemGet<SvxLRSpaceItem>(*rStyle.pFmt, RES_LR_SPACE));
1803 aLR.SetTxtLeft(nAbsLSpace);
1804 aLR.SetTxtFirstLineOfst(writer_cast<short>(nListFirstLineIndent));
1805 rStyle.pFmt->SetFmtAttr(aLR);
1806 rStyle.bListReleventIndentSet = true;
1807 }
1808 }
1809
SetStyleIndent(SwWW8StyInf & rStyle,const SwNumFmt & rFmt)1810 void SetStyleIndent(SwWW8StyInf &rStyle, const SwNumFmt &rFmt)
1811 {
1812 if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1813 {
1814 SvxLRSpaceItem aLR(ItemGet<SvxLRSpaceItem>(*rStyle.pFmt, RES_LR_SPACE));
1815 if (rStyle.bListReleventIndentSet)
1816 {
1817 SyncIndentWithList( aLR, rFmt, false, false );
1818 }
1819 else
1820 {
1821 aLR.SetTxtLeft(0);
1822 aLR.SetTxtFirstLineOfst(0);
1823 }
1824 rStyle.pFmt->SetFmtAttr(aLR);
1825 }
1826 }
1827
SetStylesList(sal_uInt16 nStyle,sal_uInt16 nActLFO,sal_uInt8 nActLevel)1828 void SwWW8ImplReader::SetStylesList(
1829 sal_uInt16 nStyle,
1830 sal_uInt16 nActLFO,
1831 sal_uInt8 nActLevel)
1832 {
1833 SwWW8StyInf &rStyleInf = pCollA[nStyle];
1834 if (rStyleInf.bValid)
1835 {
1836 ASSERT(pAktColl, "Cannot be called outside of style import");
1837 // Phase 1: Nummerierungsattribute beim Einlesen einer StyleDef
1838 if( pAktColl )
1839 {
1840 // jetzt nur die Parameter vermerken: die tatsaechliche Liste wird
1841 // spaeter drangehaengt, wenn die Listendefinitionen gelesen sind...
1842 if (
1843 (USHRT_MAX > nActLFO) &&
1844 (WW8ListManager::nMaxLevel > nActLevel)
1845 )
1846 {
1847 rStyleInf.nLFOIndex = nActLFO;
1848 rStyleInf.nListLevel = nActLevel;
1849
1850 if (
1851 (USHRT_MAX > nActLFO) &&
1852 (WW8ListManager::nMaxLevel > nActLevel)
1853 )
1854 {
1855 std::vector<sal_uInt8> aParaSprms;
1856 SwNumRule *pNmRule =
1857 pLstManager->GetNumRuleForActivation(nActLFO,
1858 nActLevel, aParaSprms);
1859 if (pNmRule)
1860 UseListIndent(rStyleInf, pNmRule->Get(nActLevel));
1861 }
1862 }
1863 }
1864 }
1865 }
1866
RegisterNumFmtOnStyle(sal_uInt16 nStyle)1867 void SwWW8ImplReader::RegisterNumFmtOnStyle( sal_uInt16 nStyle )
1868 {
1869 SwWW8StyInf &rStyleInf = pCollA[nStyle];
1870 if (rStyleInf.bValid && rStyleInf.pFmt)
1871 {
1872 // Save old pre-list modified indent, which are the word indent values
1873 rStyleInf.maWordLR =
1874 ItemGet<SvxLRSpaceItem>(*rStyleInf.pFmt, RES_LR_SPACE);
1875
1876 // Phase 2: aktualisieren der StyleDef nach einlesen aller Listen
1877 SwNumRule* pNmRule = 0;
1878 const sal_uInt16 nLFO = rStyleInf.nLFOIndex;
1879 const sal_uInt8 nLevel = rStyleInf.nListLevel;
1880 if (
1881 (USHRT_MAX > nLFO) &&
1882 (WW8ListManager::nMaxLevel > nLevel)
1883 )
1884 {
1885 std::vector<sal_uInt8> aParaSprms;
1886 pNmRule =
1887 pLstManager->GetNumRuleForActivation( nLFO, nLevel, aParaSprms );
1888
1889 if ( pNmRule != NULL )
1890 {
1891 if ( rStyleInf.IsWW8BuiltInHeadingStyle()
1892 && rStyleInf.HasWW8OutlineLevel() )
1893 {
1894 rStyleInf.pOutlineNumrule = pNmRule;
1895 }
1896 else
1897 {
1898 rStyleInf.pFmt->SetFmtAttr( SwNumRuleItem( pNmRule->GetName() ) );
1899 rStyleInf.bHasStyNumRule = true;
1900 }
1901 }
1902 }
1903
1904 if (pNmRule)
1905 SetStyleIndent(rStyleInf, pNmRule->Get(nLevel));
1906 }
1907 }
1908
RegisterNumFmtOnTxtNode(sal_uInt16 nActLFO,sal_uInt8 nActLevel,const bool bSetAttr)1909 void SwWW8ImplReader::RegisterNumFmtOnTxtNode(
1910 sal_uInt16 nActLFO,
1911 sal_uInt8 nActLevel,
1912 const bool bSetAttr)
1913 {
1914 // beachte: die Methode haengt die NumRule an den Text Node, falls
1915 // bSetAttr (dann muessen natuerlich vorher die Listen gelesen sein)
1916 // stellt sie NUR den Level ein, im Vertrauen darauf, dass am STYLE eine
1917 // NumRule haengt - dies wird NICHT ueberprueft !!!
1918
1919 if (pLstManager) // sind die Listendeklarationen gelesen?
1920 {
1921 std::vector<sal_uInt8> aParaSprms;
1922 SwTxtNode* pTxtNd = pPaM->GetNode()->GetTxtNode();
1923 ASSERT(pTxtNd, "Kein Text-Node an PaM-Position");
1924
1925 const SwNumRule* pRule =
1926 bSetAttr
1927 ? pLstManager->GetNumRuleForActivation( nActLFO, nActLevel, aParaSprms, pTxtNd)
1928 : 0;
1929
1930 if ( pRule != NULL || !bSetAttr)
1931 {
1932 if ( bSetAttr
1933 && pTxtNd->GetNumRule() != pRule
1934 && pTxtNd->GetNumRule() != rDoc.GetOutlineNumRule() )
1935 {
1936 pTxtNd->SetAttr( SwNumRuleItem( pRule->GetName() ) );
1937 }
1938
1939 pTxtNd->SetAttrListLevel(nActLevel);
1940 // - <IsCounted()> state of text node has to be adjusted accordingly.
1941 if ( /*nActLevel >= 0 &&*/ nActLevel < MAXLEVEL )
1942 {
1943 pTxtNd->SetCountedInList( true );
1944 }
1945
1946 // Direct application of the list level formatting no longer
1947 // needed for list levels of mode LABEL_ALIGNMENT
1948 bool bApplyListLevelIndentDirectlyAtPara( true );
1949 {
1950 if ( pTxtNd->GetNumRule() && nActLevel < MAXLEVEL )
1951 {
1952 const SwNumFmt& rFmt = pTxtNd->GetNumRule()->Get( nActLevel );
1953 if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
1954 {
1955 bApplyListLevelIndentDirectlyAtPara = false;
1956 }
1957 }
1958 }
1959 if ( bApplyListLevelIndentDirectlyAtPara )
1960 {
1961 SfxItemSet aListIndent(rDoc.GetAttrPool(), RES_LR_SPACE,
1962 RES_LR_SPACE);
1963 const SvxLRSpaceItem *pItem = (const SvxLRSpaceItem*)(
1964 GetFmtAttr(RES_LR_SPACE));
1965 ASSERT(pItem, "impossible");
1966 if (pItem)
1967 aListIndent.Put(*pItem);
1968
1969 /*
1970 Take the original paragraph sprms attached to this list level
1971 formatting and apply them to the paragraph. I'm convinced that
1972 this is exactly what Word does.
1973 */
1974 if (short nLen = static_cast< short >(aParaSprms.size()))
1975 {
1976 SfxItemSet* pOldAktItemSet = pAktItemSet;
1977 SetAktItemSet(&aListIndent);
1978
1979 sal_uInt8* pSprms1 = &aParaSprms[0];
1980 while (0 < nLen)
1981 {
1982 sal_uInt16 nL1 = ImportSprm(pSprms1);
1983 nLen = nLen - nL1;
1984 pSprms1 += nL1;
1985 }
1986
1987 SetAktItemSet(pOldAktItemSet);
1988 }
1989
1990 const SvxLRSpaceItem *pLR =
1991 HasItem<SvxLRSpaceItem>(aListIndent, RES_LR_SPACE);
1992 ASSERT(pLR, "Impossible");
1993 if (pLR)
1994 {
1995 pCtrlStck->NewAttr(*pPaM->GetPoint(), *pLR);
1996 pCtrlStck->SetAttr(*pPaM->GetPoint(), RES_LR_SPACE);
1997 }
1998 }
1999 }
2000 }
2001 }
2002
RegisterNumFmt(sal_uInt16 nActLFO,sal_uInt8 nActLevel)2003 void SwWW8ImplReader::RegisterNumFmt(sal_uInt16 nActLFO, sal_uInt8 nActLevel)
2004 {
2005 // sind wir erst beim Einlesen der StyleDef ?
2006 if (pAktColl)
2007 SetStylesList( nAktColl , nActLFO, nActLevel);
2008 else
2009 RegisterNumFmtOnTxtNode(nActLFO, nActLevel);
2010 }
2011
Read_ListLevel(sal_uInt16,const sal_uInt8 * pData,short nLen)2012 void SwWW8ImplReader::Read_ListLevel(sal_uInt16, const sal_uInt8* pData,
2013 short nLen)
2014 {
2015 if (pPlcxMan && pPlcxMan->GetDoingDrawTextBox())
2016 return;
2017
2018 if( nLen < 0 )
2019 {
2020 // aktuelle Liste ist hier zu Ende, was ist zu tun ???
2021 nListLevel = WW8ListManager::nMaxLevel;
2022 if (pStyles && !bVer67)
2023 pStyles->nWwNumLevel = 0;
2024 }
2025 else
2026 {
2027 // Sicherheitspruefung auf NIL Pointer
2028 if( !pData ) return;
2029 // die Streamdaten sind hier Null basiert, so wie wir es brauchen
2030 nListLevel = *pData;
2031
2032 if (pStyles && !bVer67)
2033 {
2034 /*
2035 #94672#
2036 if this is the case, then if the numbering is actually stored in
2037 WinWord 6 format, and its likely that sprmPIlvl has been abused
2038 to set the ww6 list level information which we will need when we
2039 reach the true ww6 list def. So set it now
2040 */
2041 pStyles->nWwNumLevel = nListLevel;
2042 }
2043
2044 if (WW8ListManager::nMaxLevel <= nListLevel )
2045 {
2046 // handle invalid list level value by reseting it
2047 nListLevel = WW8ListManager::nMaxLevel;
2048 }
2049 else if ( nLFOPosition < USHRT_MAX
2050 && nListLevel < WW8ListManager::nMaxLevel )
2051 {
2052 RegisterNumFmt( nLFOPosition, nListLevel );
2053 // reset kept list attributes
2054 nLFOPosition = USHRT_MAX;
2055 nListLevel = WW8ListManager::nMaxLevel;
2056 }
2057 else if ( pLstManager != NULL
2058 && pAktColl != NULL )
2059 {
2060 const sal_uInt16 nPossibleLFOPosition =
2061 pLstManager->GetPossibleLFOPosition( nAktColl, nListLevel );
2062 if ( nPossibleLFOPosition < USHRT_MAX )
2063 {
2064 // temporary register Style without reseting kept list attributes
2065 RegisterNumFmt( nPossibleLFOPosition, nListLevel );
2066 }
2067 }
2068 }
2069 }
2070
Read_LFOPosition(sal_uInt16,const sal_uInt8 * pData,short nLen)2071 void SwWW8ImplReader::Read_LFOPosition(
2072 sal_uInt16,
2073 const sal_uInt8* pData,
2074 short nLen)
2075 {
2076 if (pPlcxMan && pPlcxMan->GetDoingDrawTextBox())
2077 return;
2078
2079 if( nLen < 0 )
2080 {
2081 // aktueller Level ist hier zu Ende, was ist zu tun ???
2082 nLFOPosition = USHRT_MAX;
2083 nListLevel = WW8ListManager::nMaxLevel;
2084 }
2085 else
2086 {
2087 // Sicherheitspruefung auf NIL Pointer
2088 if( !pData )
2089 return;
2090 short nData = SVBT16ToShort( pData );
2091 if( 0 >= nData )
2092 {
2093 /*
2094 #94672# discussion
2095 If you have a paragraph in Word with left and/or hanging indent
2096 and remove its numbering, then the indentation appears to get
2097 reset, but not back to the base style, instead its goes to a blank
2098 setting.
2099 Unless its a broken ww6 list in 97 in which case more hackery is
2100 required, some more details about that in
2101 ww8par6.cxx#SwWW8ImplReader::Read_LR
2102 */
2103
2104 if (pAktColl)
2105 {
2106 pAktColl->SetFmtAttr(*GetDfltAttr( RES_PARATR_NUMRULE));
2107 pAktColl->SetFmtAttr(SvxLRSpaceItem(RES_LR_SPACE)); // #94672#
2108 }
2109 else if (SwTxtNode* pTxtNode = pPaM->GetNode()->GetTxtNode())
2110 {
2111 pTxtNode->ResetAttr( RES_PARATR_NUMRULE );
2112 pTxtNode->SetCountedInList(false);
2113
2114 /*
2115 #i24553#
2116 Hmm, I can't remove outline numbering on a per txtnode basis,
2117 but I can set some normal numbering, and that overrides outline
2118 numbering, and then I can say when I come to say that I want no
2119 number on the normal numbering rule, that should all work out
2120
2121 #115901#
2122 No special outline number in textnode any more
2123 */
2124 if (pTxtNode->IsOutline())
2125 {
2126 // Assure that the numbering rule, which is retrieved at
2127 // the paragraph is the outline numbering rule, instead of
2128 // incorrectly setting the chosen outline rule.
2129 // Note: The chosen outline rule doesn't have to correspond
2130 // to the outline rule
2131 if ( pTxtNode->GetNumRule() != rDoc.GetOutlineNumRule() )
2132 {
2133 pTxtNode->SetAttr(
2134 SwNumRuleItem( rDoc.GetOutlineNumRule()->GetName() ) );
2135 }
2136 }
2137
2138 //#94672#
2139 pCtrlStck->NewAttr(*pPaM->GetPoint(), SvxLRSpaceItem(RES_LR_SPACE));
2140 pCtrlStck->SetAttr(*pPaM->GetPoint(), RES_LR_SPACE);
2141 }
2142 nLFOPosition = USHRT_MAX;
2143 }
2144 else
2145 {
2146 nLFOPosition = (sal_uInt16)nData-1;
2147 /*
2148 #94672#
2149 If we are a ww8+ style with ww7- style lists then there is a
2150 bizarre broken Word bug where when the list is removed from a para
2151 the ww6 list first line indent still affects the first line
2152 indentation. Setting this flag will allow us to recover from this
2153 braindeadness
2154 */
2155 if ( pAktColl
2156 && (nLFOPosition == 2047-1) )
2157 {
2158 pCollA[nAktColl].bHasBrokenWW6List = true;
2159 }
2160
2161 // die Streamdaten sind hier 1 basiert, wir ziehen EINS ab
2162 if (USHRT_MAX > nLFOPosition)
2163 {
2164 if (nLFOPosition != 2047-1) // Normal ww8+ list behavior
2165 {
2166 if ( nListLevel == WW8ListManager::nMaxLevel )
2167 {
2168 nListLevel = 0;
2169 if ( pAktColl != NULL )
2170 {
2171 // temporary register Style without reseting kept list attributes
2172 RegisterNumFmt( nLFOPosition, nListLevel );
2173 }
2174 }
2175 else if (WW8ListManager::nMaxLevel > nListLevel)
2176 {
2177 RegisterNumFmt(nLFOPosition, nListLevel);
2178 // reset kept list attributes
2179 nLFOPosition = USHRT_MAX;
2180 nListLevel = WW8ListManager::nMaxLevel;
2181 }
2182 }
2183 else if (pPlcxMan && pPlcxMan->HasParaSprm(0xC63E))
2184 {
2185 /*
2186 #i8114# Horrific backwards compatible ww7- lists in ww8+ docs
2187 */
2188 Read_ANLevelNo(13 /*equiv ww7- sprm no*/, &nListLevel, 1);
2189 }
2190 }
2191 }
2192 }
2193 }
2194
2195 // -------------------------------------------------------------------
2196 // ------------------------- Reading Controls ------------------------
2197 // -------------------------------------------------------------------
2198
ImportFormulaControl(WW8FormulaControl & aFormula,WW8_CP nStart,SwWw8ControlType nWhich)2199 bool SwWW8ImplReader::ImportFormulaControl(WW8FormulaControl &aFormula,
2200 WW8_CP nStart, SwWw8ControlType nWhich )
2201 {
2202 bool bRet=false;
2203 /*
2204 * Save the reader state and process the sprms for this anchor cp.
2205 * Doing so will set the nPicLocFc to the offset to find the hypertext
2206 * data in the data stream.
2207 */
2208 WW8_CP nEndCp = nStart+1; // Only interested in the single 0x01 character
2209
2210 WW8ReaderSave aSave(this,nStart);
2211
2212 WW8PLCFManResult aRes;
2213 nStart = pPlcxMan->Where();
2214 while(nStart <= nEndCp)
2215 {
2216 if ( pPlcxMan->Get(&aRes)
2217 && aRes.pMemPos && aRes.nSprmId )
2218 {
2219 //only interested in sprms which would set nPicLocFc
2220 if ( (68 == aRes.nSprmId) || (0x6A03 == aRes.nSprmId) )
2221 {
2222 Read_PicLoc( aRes.nSprmId, aRes.pMemPos +
2223 mpSprmParser->DistanceToData(aRes.nSprmId), 4);
2224 break;
2225 }
2226 }
2227 (*pPlcxMan)++;
2228 nStart = pPlcxMan->Where();
2229 }
2230 sal_uLong nOffset = nPicLocFc;
2231 aSave.Restore(this);
2232
2233 sal_uLong nOldPos = pDataStream->Tell();
2234 WW8_PIC aPic;
2235 pDataStream->Seek( nOffset);
2236 PicRead( pDataStream, &aPic, bVer67);
2237
2238 if((aPic.lcb > 0x3A) && !pDataStream->GetError() )
2239 {
2240 aFormula.FormulaRead(nWhich,pDataStream);
2241 bRet = true;
2242 }
2243
2244 /*
2245 There is a problem with aPic, the WW8_PIC is always used even though it
2246 is too big for the WW95 files, it needs to be modified to check the
2247 version C.
2248 */
2249 pDataStream->Seek( nOldPos );
2250 return(bRet);
2251 }
2252
InsertFormula(WW8FormulaControl & rFormula)2253 sal_Bool SwMSConvertControls::InsertFormula(WW8FormulaControl &rFormula)
2254 {
2255 sal_Bool bRet = sal_False;
2256
2257 const uno::Reference< lang::XMultiServiceFactory > & rServiceFactory =
2258 GetServiceFactory();
2259
2260 if(!rServiceFactory.is())
2261 return sal_False;
2262
2263 awt::Size aSz;
2264 uno::Reference< form::XFormComponent> xFComp;
2265
2266 if (sal_True == (bRet = rFormula.Import(rServiceFactory, xFComp, aSz)))
2267 {
2268 uno::Reference <drawing::XShape> xShapeRef;
2269 if (sal_True == (bRet = InsertControl(xFComp, aSz, &xShapeRef, false)))
2270 GetShapes()->add(xShapeRef);
2271 }
2272 return bRet;
2273 }
2274
FormulaRead(SwWw8ControlType nWhich,SvStream * pDataStream)2275 void WW8FormulaControl::FormulaRead(SwWw8ControlType nWhich,
2276 SvStream *pDataStream)
2277 {
2278 sal_uInt8 nField;
2279 sal_uInt8 nHeaderByte;
2280
2281 int nType=0;
2282 *pDataStream >> nHeaderByte;
2283 if (nHeaderByte == 0xFF) // Guesswork time, difference between 97 and 95 ?
2284 {
2285 pDataStream->SeekRel(3);
2286 *pDataStream >> nHeaderByte;
2287 nType=1;
2288 }
2289 fUnknown = nHeaderByte & 0x3;
2290 fDropdownIndex = (nHeaderByte & 0x7C) >> 2;
2291 *pDataStream >> nField;
2292 fToolTip = nField & 0x01;
2293 fNoMark = (nField & 0x02)>>1;
2294 fUseSize = (nField & 0x04)>>2;
2295 fNumbersOnly= (nField & 0x08)>>3;
2296 fDateOnly = (nField & 0x10)>>4;
2297 fUnused = (nField & 0xE0)>>5;
2298 *pDataStream >> nSize;
2299
2300 *pDataStream >> hpsCheckBox;
2301 if (nType == 0)
2302 pDataStream->SeekRel(2); // Guess
2303
2304 rtl_TextEncoding eEnc = rRdr.eStructCharSet;
2305 sTitle = !nType ? WW8ReadPString(*pDataStream, eEnc, true)
2306 : WW8Read_xstz(*pDataStream, 0, true);
2307
2308 if (nWhich == WW8_CT_CHECKBOX)
2309 {
2310 *pDataStream >> nDefaultChecked;
2311 nChecked = nDefaultChecked;
2312
2313 sal_uInt8 iRes = (nHeaderByte >> 2) & 0x1F;
2314 switch (iRes)
2315 {
2316 case 1: // checked
2317 nChecked = true;
2318 break;
2319 case 25: //undefined, Undefined checkboxes are treated as unchecked
2320 case 0: // unchecked
2321 nChecked = false;
2322 break;
2323 default:
2324 ASSERT(sal_False, "unknown option, please report to cmc");
2325 break;
2326 }
2327 }
2328 else if (nWhich == WW8_CT_DROPDOWN)
2329 *pDataStream >> nChecked;
2330 else
2331 {
2332 sDefault = !nType ? WW8ReadPString(*pDataStream, eEnc, true)
2333 : WW8Read_xstz(*pDataStream, 0, true);
2334 }
2335
2336 sFormatting = !nType ? WW8ReadPString(*pDataStream, eEnc, true)
2337 : WW8Read_xstz(*pDataStream, 0, true);
2338
2339 sHelp = !nType ? WW8ReadPString(*pDataStream, eEnc, true)
2340 : WW8Read_xstz(*pDataStream, 0, true);
2341
2342 if (nWhich == WW8_CT_DROPDOWN) // is this the case ?
2343 fToolTip = true;
2344
2345 if( fToolTip )
2346 {
2347 sToolTip = !nType ? WW8ReadPString(*pDataStream, eEnc, true)
2348 : WW8Read_xstz(*pDataStream, 0, true);
2349 }
2350
2351 if (nWhich == WW8_CT_DROPDOWN)
2352 {
2353 bool bAllOk = true;
2354 pDataStream->SeekRel(4 * (nType ? 2 : 1));
2355 sal_uInt16 nDummy;
2356 *pDataStream >> nDummy;
2357 sal_uInt32 nNoStrings;
2358 if (!nType)
2359 {
2360 sal_uInt16 nWord95NoStrings;
2361 *pDataStream >> nWord95NoStrings;
2362 nNoStrings = nWord95NoStrings;
2363 *pDataStream >> nWord95NoStrings;
2364 if (nNoStrings != nWord95NoStrings)
2365 bAllOk = false;
2366 nNoStrings = nWord95NoStrings;
2367 sal_uInt16 nDummy2;
2368 *pDataStream >> nDummy2;
2369 if (nDummy2 != 0)
2370 bAllOk = false;
2371 *pDataStream >> nDummy2;
2372 if (nDummy2 != 0xA)
2373 bAllOk = false;
2374 if (!bAllOk) // Not as expected, don't risk it at all.
2375 nNoStrings = 0;
2376 for (sal_uInt16 nI = 0; nI < nNoStrings; ++nI)
2377 pDataStream->SeekRel(2);
2378 }
2379 else
2380 {
2381 if (nDummy != 0xFFFF)
2382 bAllOk = false;
2383 *pDataStream >> nNoStrings;
2384 }
2385 ASSERT(bAllOk,
2386 "Unknown formfield dropdown list structure. Report to cmc");
2387 if (!bAllOk) // Not as expected, don't risk it at all.
2388 nNoStrings = 0;
2389 maListEntries.reserve(nNoStrings);
2390 for (sal_uInt32 nI = 0; nI < nNoStrings; ++nI)
2391 {
2392 String sEntry = !nType ? WW8ReadPString(*pDataStream, eEnc, false)
2393 : WW8Read_xstz(*pDataStream, 0, false);
2394 maListEntries.push_back(sEntry);
2395 }
2396 }
2397 }
2398
WW8FormulaListBox(SwWW8ImplReader & rR)2399 WW8FormulaListBox::WW8FormulaListBox(SwWW8ImplReader &rR)
2400 : WW8FormulaControl( CREATE_CONST_ASC(SL::aListBox), rR)
2401 {
2402 }
2403
2404 //Miserable hack to get a hardcoded guesstimate of the size of a list dropdown
2405 //box's first entry to set as the lists default size
MiserableDropDownFormHack(const String & rString,uno::Reference<beans::XPropertySet> & rPropSet)2406 awt::Size SwWW8ImplReader::MiserableDropDownFormHack(const String &rString,
2407 uno::Reference<beans::XPropertySet>& rPropSet)
2408 {
2409 awt::Size aRet;
2410 struct CtrlFontMapEntry
2411 {
2412 sal_uInt16 nWhichId;
2413 const sal_Char* pPropNm;
2414 };
2415 const CtrlFontMapEntry aMapTable[] =
2416 {
2417 { RES_CHRATR_COLOR, "TextColor" },
2418 { RES_CHRATR_FONT, "FontName" },
2419 { RES_CHRATR_FONTSIZE, "FontHeight" },
2420 { RES_CHRATR_WEIGHT, "FontWeight" },
2421 { RES_CHRATR_UNDERLINE, "FontUnderline" },
2422 { RES_CHRATR_CROSSEDOUT, "FontStrikeout" },
2423 { RES_CHRATR_POSTURE, "FontSlant" },
2424 { 0, 0 }
2425 };
2426
2427 Font aFont;
2428 uno::Reference< beans::XPropertySetInfo > xPropSetInfo =
2429 rPropSet->getPropertySetInfo();
2430
2431 uno::Any aTmp;
2432 for (const CtrlFontMapEntry* pMap = aMapTable; pMap->nWhichId; ++pMap)
2433 {
2434 bool bSet = true;
2435 const SfxPoolItem* pItem = GetFmtAttr( pMap->nWhichId );
2436 ASSERT(pItem, "Impossible");
2437 if (!pItem)
2438 continue;
2439
2440 switch ( pMap->nWhichId )
2441 {
2442 case RES_CHRATR_COLOR:
2443 {
2444 String pNm;
2445 if (xPropSetInfo->hasPropertyByName(pNm = C2U("TextColor")))
2446 {
2447 aTmp <<= (sal_Int32)((SvxColorItem*)pItem)->GetValue().GetColor();
2448 rPropSet->setPropertyValue(pNm, aTmp);
2449 }
2450 }
2451 aFont.SetColor(((SvxColorItem*)pItem)->GetValue());
2452 break;
2453 case RES_CHRATR_FONT:
2454 {
2455 const SvxFontItem *pFontItem = (SvxFontItem *)pItem;
2456 String pNm;
2457 if (xPropSetInfo->hasPropertyByName(pNm = C2U("FontStyleName")))
2458 {
2459 aTmp <<= rtl::OUString( pFontItem->GetStyleName());
2460 rPropSet->setPropertyValue( pNm, aTmp );
2461 }
2462 if (xPropSetInfo->hasPropertyByName(pNm = C2U("FontFamily")))
2463 {
2464 aTmp <<= (sal_Int16)pFontItem->GetFamily();
2465 rPropSet->setPropertyValue( pNm, aTmp );
2466 }
2467 if (xPropSetInfo->hasPropertyByName(pNm = C2U("FontCharset")))
2468 {
2469 aTmp <<= (sal_Int16)pFontItem->GetCharSet();
2470 rPropSet->setPropertyValue( pNm, aTmp );
2471 }
2472 if (xPropSetInfo->hasPropertyByName(pNm = C2U("FontPitch")))
2473 {
2474 aTmp <<= (sal_Int16)pFontItem->GetPitch();
2475 rPropSet->setPropertyValue( pNm, aTmp );
2476 }
2477
2478 aTmp <<= rtl::OUString( pFontItem->GetFamilyName());
2479 aFont.SetName( pFontItem->GetFamilyName() );
2480 aFont.SetStyleName( pFontItem->GetStyleName() );
2481 aFont.SetFamily( pFontItem->GetFamily() );
2482 aFont.SetCharSet( pFontItem->GetCharSet() );
2483 aFont.SetPitch( pFontItem->GetPitch() );
2484 }
2485 break;
2486
2487 case RES_CHRATR_FONTSIZE:
2488 {
2489 Size aSize( aFont.GetSize().Width(),
2490 ((SvxFontHeightItem*)pItem)->GetHeight() );
2491 aTmp <<= ((float)aSize.Height()) / 20.0;
2492
2493 aFont.SetSize(OutputDevice::LogicToLogic(aSize, MAP_TWIP,
2494 MAP_100TH_MM));
2495 }
2496 break;
2497
2498 case RES_CHRATR_WEIGHT:
2499 aTmp <<= (float)VCLUnoHelper::ConvertFontWeight(
2500 ((SvxWeightItem*)pItem)->GetWeight() );
2501 aFont.SetWeight( ((SvxWeightItem*)pItem)->GetWeight() );
2502 break;
2503
2504 case RES_CHRATR_UNDERLINE:
2505 aTmp <<= (sal_Int16)(((SvxUnderlineItem*)pItem)->GetLineStyle());
2506 aFont.SetUnderline(((SvxUnderlineItem*)pItem)->GetLineStyle());
2507 break;
2508
2509 case RES_CHRATR_CROSSEDOUT:
2510 aTmp <<= (sal_Int16)( ((SvxCrossedOutItem*)pItem)->GetStrikeout() );
2511 aFont.SetStrikeout( ((SvxCrossedOutItem*)pItem)->GetStrikeout() );
2512 break;
2513
2514 case RES_CHRATR_POSTURE:
2515 aTmp <<= (sal_Int16)( ((SvxPostureItem*)pItem)->GetPosture() );
2516 aFont.SetItalic( ((SvxPostureItem*)pItem)->GetPosture() );
2517 break;
2518
2519 default:
2520 bSet = false;
2521 break;
2522 }
2523
2524 if (bSet && xPropSetInfo->hasPropertyByName(C2U(pMap->pPropNm)))
2525 rPropSet->setPropertyValue(C2U(pMap->pPropNm), aTmp);
2526 }
2527 // now calculate the size of the control
2528 OutputDevice* pOut = Application::GetDefaultDevice();
2529 ASSERT(pOut, "Impossible");
2530 if (pOut)
2531 {
2532 pOut->Push( PUSH_FONT | PUSH_MAPMODE );
2533 pOut->SetMapMode( MapMode( MAP_100TH_MM ));
2534 pOut->SetFont( aFont );
2535 aRet.Width = pOut->GetTextWidth(rString);
2536 aRet.Width += 500; //plus size of button, total hack territory
2537 aRet.Height = pOut->GetTextHeight();
2538 pOut->Pop();
2539 }
2540 return aRet;
2541 }
2542
Import(const uno::Reference<lang::XMultiServiceFactory> & rServiceFactory,uno::Reference<form::XFormComponent> & rFComp,awt::Size & rSz)2543 sal_Bool WW8FormulaListBox::Import(const uno::Reference <
2544 lang::XMultiServiceFactory> &rServiceFactory,
2545 uno::Reference <form::XFormComponent> &rFComp,awt::Size &rSz )
2546 {
2547 uno::Reference<uno::XInterface> xCreate = rServiceFactory->createInstance(
2548 C2U("com.sun.star.form.component.ComboBox"));
2549 if( !xCreate.is() )
2550 return sal_False;
2551
2552 rFComp = uno::Reference<form::XFormComponent>(xCreate, uno::UNO_QUERY);
2553 if( !rFComp.is() )
2554 return sal_False;
2555
2556 uno::Reference<beans::XPropertySet> xPropSet(xCreate, uno::UNO_QUERY);
2557
2558 uno::Any aTmp;
2559 if (sTitle.Len())
2560 aTmp <<= rtl::OUString(sTitle);
2561 else
2562 aTmp <<= rtl::OUString(sName);
2563 xPropSet->setPropertyValue(C2U("Name"), aTmp );
2564
2565 if (sToolTip.Len())
2566 {
2567 aTmp <<= rtl::OUString(sToolTip);
2568 xPropSet->setPropertyValue(C2U("HelpText"), aTmp );
2569 }
2570
2571 sal_Bool bDropDown(sal_True);
2572 xPropSet->setPropertyValue(C2U("Dropdown"), cppu::bool2any(bDropDown));
2573
2574 if (!maListEntries.empty())
2575 {
2576 sal_uInt32 nLen = maListEntries.size();
2577 uno::Sequence< ::rtl::OUString > aListSource(nLen);
2578 for (sal_uInt32 nI = 0; nI < nLen; ++nI)
2579 aListSource[nI] = rtl::OUString(maListEntries[nI]);
2580 aTmp <<= aListSource;
2581 xPropSet->setPropertyValue(C2U("StringItemList"), aTmp );
2582
2583 if (fDropdownIndex < nLen)
2584 {
2585 aTmp <<= aListSource[fDropdownIndex];
2586 }
2587 else
2588 {
2589 aTmp <<= aListSource[0];
2590 }
2591
2592 xPropSet->setPropertyValue(C2U("DefaultText"), aTmp );
2593
2594 rSz = rRdr.MiserableDropDownFormHack(maListEntries[0], xPropSet);
2595 }
2596 else
2597 {
2598 static const sal_Unicode aBlank[] =
2599 {
2600 0x2002,0x2002,0x2002,0x2002,0x2002
2601 };
2602 rSz = rRdr.MiserableDropDownFormHack(String(aBlank), xPropSet);
2603 }
2604
2605 return sal_True;
2606 }
2607
WW8FormulaCheckBox(SwWW8ImplReader & rR)2608 WW8FormulaCheckBox::WW8FormulaCheckBox(SwWW8ImplReader &rR)
2609 : WW8FormulaControl( CREATE_CONST_ASC(SL::aCheckBox), rR)
2610 {
2611 }
2612
lcl_AddToPropertyContainer(uno::Reference<beans::XPropertySet> xPropSet,const rtl::OUString & rPropertyName,const rtl::OUString & rValue)2613 static void lcl_AddToPropertyContainer
2614 (uno::Reference<beans::XPropertySet> xPropSet,
2615 const rtl::OUString & rPropertyName, const rtl::OUString & rValue)
2616 {
2617 uno::Reference<beans::XPropertySetInfo> xPropSetInfo =
2618 xPropSet->getPropertySetInfo();
2619 if (xPropSetInfo.is() &&
2620 ! xPropSetInfo->hasPropertyByName(rPropertyName))
2621 {
2622 uno::Reference<beans::XPropertyContainer>
2623 xPropContainer(xPropSet, uno::UNO_QUERY);
2624 uno::Any aAny(C2U(""));
2625 xPropContainer->addProperty
2626 (rPropertyName,
2627 static_cast<sal_Int16>(beans::PropertyAttribute::BOUND |
2628 beans::PropertyAttribute::REMOVABLE),
2629 aAny);
2630 }
2631
2632 uno::Any aAnyValue(rValue);
2633 xPropSet->setPropertyValue(rPropertyName, aAnyValue );
2634 }
2635
Import(const uno::Reference<lang::XMultiServiceFactory> & rServiceFactory,uno::Reference<form::XFormComponent> & rFComp,awt::Size & rSz)2636 sal_Bool WW8FormulaCheckBox::Import(const uno::Reference <
2637 lang::XMultiServiceFactory> &rServiceFactory,
2638 uno::Reference <form::XFormComponent> &rFComp,awt::Size &rSz )
2639 {
2640 uno::Reference< uno::XInterface > xCreate = rServiceFactory->createInstance(
2641 C2U("com.sun.star.form.component.CheckBox"));
2642 if( !xCreate.is() )
2643 return sal_False;
2644
2645 rFComp = uno::Reference< form::XFormComponent >( xCreate, uno::UNO_QUERY );
2646 if( !rFComp.is() )
2647 return sal_False;
2648
2649 uno::Reference< beans::XPropertySet > xPropSet( xCreate, uno::UNO_QUERY );
2650
2651 rSz.Width = 16 * hpsCheckBox;
2652 rSz.Height = 16 * hpsCheckBox;
2653
2654 uno::Any aTmp;
2655 if (sTitle.Len())
2656 aTmp <<= rtl::OUString(sTitle);
2657 else
2658 aTmp <<= rtl::OUString(sName);
2659 xPropSet->setPropertyValue(C2U("Name"), aTmp );
2660
2661 aTmp <<= (sal_Int16)nChecked;
2662 xPropSet->setPropertyValue(C2U("DefaultState"), aTmp);
2663
2664 if( sToolTip.Len() )
2665 lcl_AddToPropertyContainer(xPropSet, C2U("HelpText"), sToolTip);
2666
2667 if( sHelp.Len() )
2668 lcl_AddToPropertyContainer(xPropSet, C2U("HelpF1Text"), sHelp);
2669
2670 return sal_True;
2671
2672 }
2673
WW8FormulaEditBox(SwWW8ImplReader & rR)2674 WW8FormulaEditBox::WW8FormulaEditBox(SwWW8ImplReader &rR)
2675 : WW8FormulaControl( CREATE_CONST_ASC(SL::aTextField) ,rR)
2676 {
2677 }
2678
InsertControl(const uno::Reference<form::XFormComponent> & rFComp,const awt::Size & rSize,uno::Reference<drawing::XShape> * pShape,sal_Bool bFloatingCtrl)2679 sal_Bool SwMSConvertControls::InsertControl(
2680 const uno::Reference< form::XFormComponent > & rFComp,
2681 const awt::Size& rSize, uno::Reference< drawing::XShape > *pShape,
2682 sal_Bool bFloatingCtrl)
2683 {
2684 const uno::Reference< container::XIndexContainer > &rComps = GetFormComps();
2685 uno::Any aTmp( &rFComp, ::getCppuType((const uno::Reference<
2686 form::XFormComponent >*)0) );
2687 rComps->insertByIndex( rComps->getCount(), aTmp );
2688
2689 const uno::Reference< lang::XMultiServiceFactory > &rServiceFactory =
2690 GetServiceFactory();
2691 if( !rServiceFactory.is() )
2692 return sal_False;
2693
2694 uno::Reference< uno::XInterface > xCreate = rServiceFactory->createInstance(
2695 C2U("com.sun.star.drawing.ControlShape"));
2696 if( !xCreate.is() )
2697 return sal_False;
2698
2699 uno::Reference< drawing::XShape > xShape =
2700 uno::Reference< drawing::XShape >(xCreate, uno::UNO_QUERY);
2701
2702 DBG_ASSERT(xShape.is(), "XShape nicht erhalten");
2703 xShape->setSize(rSize);
2704
2705 uno::Reference< beans::XPropertySet > xShapePropSet(
2706 xCreate, uno::UNO_QUERY );
2707
2708 //I lay a small bet that this will change to
2709 //sal_Int16 nTemp=TextContentAnchorType::AS_CHARACTER;
2710 sal_Int16 nTemp;
2711 if (bFloatingCtrl)
2712 nTemp= text::TextContentAnchorType_AT_PARAGRAPH;
2713 else
2714 nTemp= text::TextContentAnchorType_AS_CHARACTER;
2715
2716 aTmp <<= nTemp;
2717 xShapePropSet->setPropertyValue(C2U("AnchorType"), aTmp );
2718
2719 nTemp= text::VertOrientation::TOP;
2720 aTmp <<= nTemp;
2721 xShapePropSet->setPropertyValue(C2U("VertOrient"), aTmp );
2722
2723 uno::Reference< text::XText > xDummyTxtRef;
2724 uno::Reference< text::XTextRange > xTxtRg =
2725 new SwXTextRange( *pPaM, xDummyTxtRef );
2726
2727 aTmp.setValue(&xTxtRg,::getCppuType((
2728 uno::Reference< text::XTextRange >*)0));
2729 xShapePropSet->setPropertyValue(C2U("TextRange"), aTmp );
2730
2731 // Das Control-Model am Control-Shape setzen
2732 uno::Reference< drawing::XControlShape > xControlShape( xShape,
2733 uno::UNO_QUERY );
2734 uno::Reference< awt::XControlModel > xControlModel( rFComp,
2735 uno::UNO_QUERY );
2736 xControlShape->setControl( xControlModel );
2737
2738 if (pShape)
2739 *pShape = xShape;
2740
2741 return sal_True;
2742 }
2743
2744 /* vim: set noet sw=4 ts=4: */
2745