LibreOffice Module sw (master)  1
poolfmt.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <memory>
21 #include <hintids.hxx>
22 #include <i18nlangtag/mslangid.hxx>
24 #include <editeng/paperinf.hxx>
25 #include <editeng/wghtitem.hxx>
26 #include <editeng/fontitem.hxx>
27 #include <editeng/fhgtitem.hxx>
28 #include <editeng/tstpitem.hxx>
29 #include <editeng/lrspitem.hxx>
30 #include <editeng/ulspitem.hxx>
31 #include <editeng/lspcitem.hxx>
32 #include <editeng/adjustitem.hxx>
33 #include <editeng/postitem.hxx>
34 #include <editeng/keepitem.hxx>
35 #include <editeng/opaqitem.hxx>
36 #include <editeng/boxitem.hxx>
37 #include <editeng/cmapitem.hxx>
38 #include <editeng/udlnitem.hxx>
39 #include <editeng/colritem.hxx>
40 #include <editeng/protitem.hxx>
42 #include <editeng/langitem.hxx>
44 #include <editeng/frmdiritem.hxx>
47 #include <viewopt.hxx>
48 #include <doc.hxx>
49 #include <IDocumentUndoRedo.hxx>
51 #include <IDocumentState.hxx>
53 #include <fmtanchr.hxx>
54 #include <fmtornt.hxx>
55 #include <fmtsrnd.hxx>
56 #include <fmtfsize.hxx>
57 #include <poolfmt.hxx>
58 #include <paratr.hxx>
59 #include <pagedesc.hxx>
60 #include <frmtool.hxx>
61 #include <charfmt.hxx>
62 #include <docary.hxx>
63 #include <fmtcol.hxx>
64 #include <ndtxt.hxx>
65 #include <fmtline.hxx>
66 #include <GetMetricVal.hxx>
67 #include <numrule.hxx>
68 #include <swtable.hxx>
69 #include <tblafmt.hxx>
70 #include <hints.hxx>
71 #include <svx/xdef.hxx>
72 #include <svx/xfillit0.hxx>
73 
74 using namespace ::editeng;
75 using namespace ::com::sun::star;
76 
77 void SetAllScriptItem( SfxItemSet& rSet, const SfxPoolItem& rItem )
78 {
79  rSet.Put( rItem );
80  sal_uInt16 nWhCJK = 0, nWhCTL = 0;
81  switch( rItem.Which() )
82  {
84  nWhCJK = RES_CHRATR_CJK_FONTSIZE;
85  nWhCTL = RES_CHRATR_CTL_FONTSIZE;
86  break;
87  case RES_CHRATR_FONT:
88  nWhCJK = RES_CHRATR_CJK_FONT;
89  nWhCTL = RES_CHRATR_CTL_FONT;
90  break;
92  nWhCJK = RES_CHRATR_CJK_LANGUAGE;
93  nWhCTL = RES_CHRATR_CTL_LANGUAGE;
94  break;
95  case RES_CHRATR_POSTURE:
96  nWhCJK = RES_CHRATR_CJK_POSTURE;
97  nWhCTL = RES_CHRATR_CTL_POSTURE;
98  break;
99  case RES_CHRATR_WEIGHT:
100  nWhCJK = RES_CHRATR_CJK_WEIGHT;
101  nWhCTL = RES_CHRATR_CTL_WEIGHT;
102  break;
103  }
104 
105  if( nWhCJK )
106  rSet.Put( rItem.CloneSetWhich(nWhCJK) );
107  if( nWhCTL )
108  rSet.Put( rItem.CloneSetWhich(nWhCTL) );
109 }
110 
116 {
117  return MsLangId::isRightToLeft(nLanguage) ?
118  SvxFrameDirection::Horizontal_RL_TB : SvxFrameDirection::Horizontal_LR_TB;
119 }
120 
121 // See if the Paragraph/Character/Frame/Page style is in use
122 bool SwDoc::IsUsed( const SwModify& rModify ) const
123 {
124  // Check if we have dependent ContentNodes in the Nodes array
125  // (also indirect ones for derived Formats)
126  SwAutoFormatGetDocNode aGetHt( &GetNodes() );
127  return !rModify.GetInfo( aGetHt );
128 }
129 
130 // See if Table style is in use
131 bool SwDoc::IsUsed( const SwTableAutoFormat& rTableAutoFormat) const
132 {
133  size_t nTableCount = GetTableFrameFormatCount(true);
134  for (size_t i=0; i < nTableCount; ++i)
135  {
136  SwFrameFormat* pFrameFormat = &GetTableFrameFormat(i, true);
137  SwTable* pTable = SwTable::FindTable(pFrameFormat);
138  if (pTable->GetTableStyleName() == rTableAutoFormat.GetName())
139  return true;
140  }
141  return false;
142 }
143 
144 // See if the NumRule is used
145 bool SwDoc::IsUsed( const SwNumRule& rRule )
146 {
147  bool bUsed = rRule.GetTextNodeListSize() > 0 ||
148  rRule.GetParagraphStyleListSize() > 0;
149 
150  return bUsed;
151 }
152 
153 const OUString* SwDoc::GetDocPattern(size_t const nPos) const
154 {
155  if (nPos >= m_PatternNames.size())
156  return nullptr;
157  return &m_PatternNames[nPos];
158 }
159 
160 // Look for the style name's position. If it doesn't exist,
161 // insert a anew
162 size_t SwDoc::SetDocPattern(const OUString& rPatternName)
163 {
164  OSL_ENSURE( !rPatternName.isEmpty(), "no Document style name" );
165 
166  auto const iter(
167  std::find(m_PatternNames.begin(), m_PatternNames.end(), rPatternName));
168  if (iter != m_PatternNames.end())
169  {
170  return std::distance(m_PatternNames.begin(), iter);
171  }
172  else
173  {
174  m_PatternNames.push_back(rPatternName);
176  return m_PatternNames.size() - 1;
177  }
178 }
179 
180 sal_uInt16 GetPoolParent( sal_uInt16 nId )
181 {
182  sal_uInt16 nRet = USHRT_MAX;
183  if( POOLGRP_NOCOLLID & nId ) // 1 == Formats / 0 == Collections
184  {
185  switch( ( COLL_GET_RANGE_BITS | POOLGRP_NOCOLLID ) & nId )
186  {
187  case POOLGRP_CHARFMT:
188  case POOLGRP_FRAMEFMT:
189  nRet = 0; // derived from the default
190  break;
191  case POOLGRP_PAGEDESC:
192  case POOLGRP_NUMRULE:
193  break; // there are no derivations
194  }
195  }
196  else
197  {
198  switch( COLL_GET_RANGE_BITS & nId )
199  {
200  case COLL_TEXT_BITS:
201  switch( nId )
202  {
204  nRet = 0; break;
210  nRet = RES_POOLCOLL_TEXT; break;
211 
212  case RES_POOLCOLL_TEXT:
216  nRet = RES_POOLCOLL_STANDARD; break;
217 
228  nRet = RES_POOLCOLL_HEADLINE_BASE; break;
229  }
230  break;
231 
232  case COLL_LISTS_BITS:
233  switch( nId )
234  {
236  nRet = RES_POOLCOLL_TEXT; break;
237 
238  default:
239  nRet = RES_POOLCOLL_NUMBUL_BASE; break;
240  }
241  break;
242 
243  case COLL_EXTRA_BITS:
244  switch( nId )
245  {
247  nRet = RES_POOLCOLL_TABLE; break;
248 
249  case RES_POOLCOLL_FRAME:
250  case RES_POOLCOLL_TABLE:
256  case RES_POOLCOLL_LABEL:
257  nRet = RES_POOLCOLL_STANDARD; break;
258  case RES_POOLCOLL_HEADER:
259  nRet = RES_POOLCOLL_HEADERFOOTER; break;
262  nRet = RES_POOLCOLL_HEADER; break;
263  case RES_POOLCOLL_FOOTER:
264  nRet = RES_POOLCOLL_HEADERFOOTER; break;
267  nRet = RES_POOLCOLL_FOOTER; break;
268 
274  nRet = RES_POOLCOLL_LABEL; break;
275  }
276  break;
277 
278  case COLL_REGISTER_BITS:
279  switch( nId )
280  {
282  nRet = RES_POOLCOLL_STANDARD; break;
283 
291  nRet = RES_POOLCOLL_HEADLINE_BASE; break;
292 
293  default:
294  nRet = RES_POOLCOLL_REGISTER_BASE; break;
295  }
296  break;
297 
298  case COLL_DOC_BITS:
300  break;
301 
302  case COLL_HTML_BITS:
303  nRet = RES_POOLCOLL_STANDARD;
304  break;
305  }
306  }
307 
308  return nRet;
309 }
310 
312 {
313  /* Restore the language independent pool defaults and styles. */
315 
317 
318  pTextFormatColl->ResetFormatAttr( RES_PARATR_ADJUST );
319  /* koreans do not like SvxScriptItem(TRUE) */
320  pTextFormatColl->ResetFormatAttr( RES_PARATR_SCRIPTSPACE );
321 
322  SvxFrameDirectionItem aFrameDir( SvxFrameDirection::Horizontal_LR_TB, RES_FRAMEDIR );
323 
324  size_t nCount = GetPageDescCnt();
325  for( size_t i=0; i<nCount; ++i )
326  {
327  SwPageDesc& rDesc = GetPageDesc( i );
328  rDesc.GetMaster().SetFormatAttr( aFrameDir );
329  rDesc.GetLeft().SetFormatAttr( aFrameDir );
330  }
331 
332  //#i16874# AutoKerning as default for new documents
334 }
335 
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Subgroup labels.
Definition: poolfmt.hxx:345
#define RES_CHRATR_WEIGHT
Definition: hintids.hxx:83
const sal_uInt16 COLL_LISTS_BITS
Definition: poolfmt.hxx:67
const sal_uInt16 COLL_DOC_BITS
Definition: poolfmt.hxx:70
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
#define RES_CHRATR_CJK_LANGUAGE
Definition: hintids.hxx:92
SwFrameFormat & GetLeft()
Definition: pagedesc.hxx:217
#define RES_CHRATR_FONTSIZE
Definition: hintids.hxx:76
#define RES_CHRATR_LANGUAGE
Definition: hintids.hxx:78
const sal_uInt16 COLL_GET_RANGE_BITS
Definition: poolfmt.hxx:72
std::vector< OUString > m_PatternNames
Definition: doc.hxx:203
#define RES_CHRATR_CJK_POSTURE
Definition: hintids.hxx:93
Header Left.
Definition: poolfmt.hxx:332
virtual void SetModified()=0
Must be called manually at changes of format.
Subgroup user indices.
Definition: poolfmt.hxx:382
#define RES_FRAMEDIR
Definition: hintids.hxx:225
const sal_uInt16 COLL_HTML_BITS
Definition: poolfmt.hxx:71
#define RES_CHRATR_CJK_WEIGHT
Definition: hintids.hxx:94
sal_uInt16 GetPoolParent(sal_uInt16 nId)
Query defined parent of a POOL-ID Returns 0 if standard USHRT_MAX if no parent the parent in all othe...
Definition: poolfmt.cxx:180
#define RES_CHRATR_FONT
Definition: hintids.hxx:75
SvxFrameDirection
#define RES_CHRATR_CJK_FONT
Definition: hintids.hxx:90
#define RES_CHRATR_CJK_FONTSIZE
Definition: hintids.hxx:91
virtual bool GetInfo(SfxPoolItem &) const override
Definition: calbck.cxx:206
#define RES_CHRATR_CTL_FONTSIZE
Definition: hintids.hxx:96
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:458
Subgroup header.
Definition: poolfmt.hxx:330
void SetAllScriptItem(SfxItemSet &rSet, const SfxPoolItem &rItem)
Definition: poolfmt.cxx:77
const OUString & GetTableStyleName() const
Return the table style name of this table.
Definition: swtable.hxx:188
Text body indent.
Definition: poolfmt.hxx:254
const sal_uInt16 COLL_REGISTER_BITS
Definition: poolfmt.hxx:69
const sal_uInt16 POOLGRP_NOCOLLID
POOLCOLL-IDs: +-—+—+—+—+—+—+—+—+—+—+—+—+—+—+—+—+ !User! Range ! 0 ! Offset ! +-—+—+...
Definition: poolfmt.hxx:59
Other stuff.
Definition: poolfmt.hxx:352
object index.
Definition: poolfmt.hxx:400
Table of Contents - heading.
Definition: poolfmt.hxx:342
static SwTable * FindTable(SwFrameFormat const *const pFormat)
Definition: swtable.cxx:1920
Style of a layout element.
Definition: frmfmt.hxx:57
static bool isRightToLeft(LanguageType nLang)
Complimentary close.
Definition: poolfmt.hxx:255
#define RES_CHRATR_CTL_FONT
Definition: hintids.hxx:95
size_t SetDocPattern(const OUString &rPatternName)
Definition: poolfmt.cxx:162
Subgroup headings.
Definition: poolfmt.hxx:261
Subgroup footer.
Definition: poolfmt.hxx:336
const SwPageDesc & GetPageDesc(const size_t i) const
Definition: doc.hxx:875
Text body.
Definition: poolfmt.hxx:251
int i
#define RES_PARATR_SCRIPTSPACE
Definition: hintids.hxx:171
size_t GetPageDescCnt() const
Definition: doc.hxx:874
Header Left&Right.
Definition: poolfmt.hxx:331
const sal_uInt16 POOLGRP_PAGEDESC
Definition: poolfmt.hxx:78
Header Right.
Definition: poolfmt.hxx:333
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:426
Label drawing objects.
Definition: poolfmt.hxx:358
const OUString * GetDocPattern(size_t nPos) const
Definition: poolfmt.cxx:153
std::unique_ptr< SfxPoolItem > CloneSetWhich(sal_uInt16 nNewWhich) const
SwNumRule::tParagraphStyleList::size_type GetParagraphStyleListSize() const
Definition: number.cxx:992
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:110
Text body first line indent.
Definition: poolfmt.hxx:252
const sal_uInt16 POOLGRP_FRAMEFMT
Definition: poolfmt.hxx:77
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:460
const OUString & GetName() const
Definition: tblafmt.hxx:225
illustrations index.
Definition: poolfmt.hxx:396
SwFrameFormat & GetMaster()
Definition: pagedesc.hxx:216
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SwNumRule::tTextNodeList::size_type GetTextNodeListSize() const
Definition: number.cxx:132
#define RES_CHRATR_CTL_LANGUAGE
Definition: hintids.hxx:97
#define RES_CHRATR_POSTURE
Definition: hintids.hxx:79
#define RES_CHRATR_CTL_WEIGHT
Definition: hintids.hxx:99
#define RES_CHRATR_CTL_POSTURE
Definition: hintids.hxx:98
void ResetPoolDefaultItem(sal_uInt16 nWhich)
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:259
Marginalia.
Definition: poolfmt.hxx:258
const sal_uInt16 POOLGRP_NUMRULE
Definition: poolfmt.hxx:79
bool IsUsed(const SwModify &) const
Definition: poolfmt.cxx:122
SwNodes & GetNodes()
Definition: doc.hxx:403
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
#define RES_PARATR_ADJUST
Definition: hintids.hxx:162
Label illustration.
Definition: poolfmt.hxx:346
size_t GetTableFrameFormatCount(bool bUsed) const
Definition: docfmt.cxx:782
tables index.
Definition: poolfmt.hxx:404
virtual bool ResetFormatAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0) override
Definition: fmtcol.cxx:367
SwFrameFormat & GetTableFrameFormat(size_t nFormat, bool bUsed) const
Definition: docfmt.cxx:799
SvxFrameDirection GetDefaultFrameDirection(LanguageType nLanguage)
Return the AutoCollection by its Id.
Definition: poolfmt.cxx:115
void RemoveAllFormatLanguageDependencies()
Definition: poolfmt.cxx:311
#define RES_CHRATR_AUTOKERN
Definition: hintids.hxx:85
Footer Left.
Definition: poolfmt.hxx:337
Subgroup index tables.
Definition: poolfmt.hxx:367
Text body hanging indent.
Definition: poolfmt.hxx:253
Subgroup table of contents.
Definition: poolfmt.hxx:374
const sal_uInt16 COLL_TEXT_BITS
Definition: poolfmt.hxx:66
Subgroup table.
Definition: poolfmt.hxx:341
index of authorities.
Definition: poolfmt.hxx:408
const sal_uInt16 POOLGRP_CHARFMT
Other groups:
Definition: poolfmt.hxx:76
Footer Right.
Definition: poolfmt.hxx:338
sal_uInt16 Which() const
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1307
const sal_uInt16 COLL_EXTRA_BITS
Definition: poolfmt.hxx:68