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 <hintids.hxx>
21 #include <i18nlangtag/mslangid.hxx>
22 #include <editeng/boxitem.hxx>
23 #include <editeng/frmdiritem.hxx>
24 #include <osl/diagnose.h>
25 #include <doc.hxx>
26 #include <IDocumentState.hxx>
28 #include <IDocumentListsAccess.hxx>
29 #include <list.hxx>
30 #include <poolfmt.hxx>
31 #include <pagedesc.hxx>
32 #include <fmtcol.hxx>
33 #include <numrule.hxx>
34 #include <swtable.hxx>
35 #include <tblafmt.hxx>
36 #include <hints.hxx>
37 
38 using namespace ::editeng;
39 using namespace ::com::sun::star;
40 
41 void SetAllScriptItem( SfxItemSet& rSet, const SfxPoolItem& rItem )
42 {
43  rSet.Put( rItem );
44  sal_uInt16 nWhCJK = 0, nWhCTL = 0;
45  switch( rItem.Which() )
46  {
48  nWhCJK = RES_CHRATR_CJK_FONTSIZE;
49  nWhCTL = RES_CHRATR_CTL_FONTSIZE;
50  break;
51  case RES_CHRATR_FONT:
52  nWhCJK = RES_CHRATR_CJK_FONT;
53  nWhCTL = RES_CHRATR_CTL_FONT;
54  break;
56  nWhCJK = RES_CHRATR_CJK_LANGUAGE;
57  nWhCTL = RES_CHRATR_CTL_LANGUAGE;
58  break;
59  case RES_CHRATR_POSTURE:
60  nWhCJK = RES_CHRATR_CJK_POSTURE;
61  nWhCTL = RES_CHRATR_CTL_POSTURE;
62  break;
63  case RES_CHRATR_WEIGHT:
64  nWhCJK = RES_CHRATR_CJK_WEIGHT;
65  nWhCTL = RES_CHRATR_CTL_WEIGHT;
66  break;
67  }
68 
69  if( nWhCJK )
70  rSet.Put( rItem.CloneSetWhich(nWhCJK) );
71  if( nWhCTL )
72  rSet.Put( rItem.CloneSetWhich(nWhCTL) );
73 }
74 
80 {
81  return MsLangId::isRightToLeft(nLanguage) ?
82  SvxFrameDirection::Horizontal_RL_TB : SvxFrameDirection::Horizontal_LR_TB;
83 }
84 
85 // See if the Paragraph/Character/Frame/Page style is in use
86 bool SwDoc::IsUsed( const sw::BroadcastingModify& rModify ) const
87 {
88  // Check if we have dependent ContentNodes in the Nodes array
89  // (also indirect ones for derived Formats)
90  SwAutoFormatGetDocNode aGetHt( &GetNodes() );
91  return !rModify.GetInfo( aGetHt );
92 }
93 
94 // See if Table style is in use
95 bool SwDoc::IsUsed( const SwTableAutoFormat& rTableAutoFormat) const
96 {
97  size_t nTableCount = GetTableFrameFormatCount(true);
98  for (size_t i=0; i < nTableCount; ++i)
99  {
100  SwFrameFormat* pFrameFormat = &GetTableFrameFormat(i, true);
101  SwTable* pTable = SwTable::FindTable(pFrameFormat);
102  if (pTable->GetTableStyleName() == rTableAutoFormat.GetName())
103  return true;
104  }
105  return false;
106 }
107 
108 // See if the NumRule is used
109 bool SwDoc::IsUsed( const SwNumRule& rRule )
110 {
111  SwList const*const pList(getIDocumentListsAccess().getListByName(rRule.GetDefaultListId()));
112  bool bUsed = rRule.GetTextNodeListSize() > 0 ||
113  rRule.GetParagraphStyleListSize() > 0 ||
114  rRule.IsUsedByRedline()
115  // tdf#135014 default num rule is used if any associated num rule is used
116  || (pList
117  && pList->GetDefaultListStyleName() == rRule.GetName()
118  && pList->HasNodes());
119 
120  return bUsed;
121 }
122 
123 const OUString* SwDoc::GetDocPattern(size_t const nPos) const
124 {
125  if (nPos >= m_PatternNames.size())
126  return nullptr;
127  return &m_PatternNames[nPos];
128 }
129 
130 // Look for the style name's position. If it doesn't exist,
131 // insert an anew
132 size_t SwDoc::SetDocPattern(const OUString& rPatternName)
133 {
134  OSL_ENSURE( !rPatternName.isEmpty(), "no Document style name" );
135 
136  auto const iter(
137  std::find(m_PatternNames.begin(), m_PatternNames.end(), rPatternName));
138  if (iter != m_PatternNames.end())
139  {
140  return std::distance(m_PatternNames.begin(), iter);
141  }
142  else
143  {
144  m_PatternNames.push_back(rPatternName);
146  return m_PatternNames.size() - 1;
147  }
148 }
149 
150 sal_uInt16 GetPoolParent( sal_uInt16 nId )
151 {
152  sal_uInt16 nRet = USHRT_MAX;
153  if( POOLGRP_NOCOLLID & nId ) // 1 == Formats / 0 == Collections
154  {
155  switch( ( COLL_GET_RANGE_BITS | POOLGRP_NOCOLLID ) & nId )
156  {
157  case POOLGRP_CHARFMT:
158  case POOLGRP_FRAMEFMT:
159  nRet = 0; // derived from the default
160  break;
161  case POOLGRP_PAGEDESC:
162  case POOLGRP_NUMRULE:
163  break; // there are no derivations
164  }
165  }
166  else
167  {
168  switch( COLL_GET_RANGE_BITS & nId )
169  {
170  case COLL_TEXT_BITS:
171  switch( nId )
172  {
174  nRet = 0; break;
180  nRet = RES_POOLCOLL_TEXT; break;
181 
182  case RES_POOLCOLL_TEXT:
186  nRet = RES_POOLCOLL_STANDARD; break;
187 
198  nRet = RES_POOLCOLL_HEADLINE_BASE; break;
199  }
200  break;
201 
202  case COLL_LISTS_BITS:
203  switch( nId )
204  {
206  nRet = RES_POOLCOLL_TEXT; break;
207 
208  default:
209  nRet = RES_POOLCOLL_NUMBER_BULLET_BASE; break;
210  }
211  break;
212 
213  case COLL_EXTRA_BITS:
214  switch( nId )
215  {
217  nRet = RES_POOLCOLL_TABLE; break;
218 
219  case RES_POOLCOLL_FRAME:
220  case RES_POOLCOLL_TABLE:
226  case RES_POOLCOLL_LABEL:
227  nRet = RES_POOLCOLL_STANDARD; break;
228  case RES_POOLCOLL_HEADER:
229  nRet = RES_POOLCOLL_HEADERFOOTER; break;
232  nRet = RES_POOLCOLL_HEADER; break;
233  case RES_POOLCOLL_FOOTER:
234  nRet = RES_POOLCOLL_HEADERFOOTER; break;
237  nRet = RES_POOLCOLL_FOOTER; break;
238 
244  nRet = RES_POOLCOLL_LABEL; break;
245  }
246  break;
247 
248  case COLL_REGISTER_BITS:
249  switch( nId )
250  {
252  nRet = RES_POOLCOLL_STANDARD; break;
253 
255  nRet = RES_POOLCOLL_HEADLINE_BASE; break;
256 
263  nRet = RES_POOLCOLL_TOX_IDXH; break;
264 
265  default:
266  nRet = RES_POOLCOLL_REGISTER_BASE; break;
267  }
268  break;
269 
270  case COLL_DOC_BITS:
272  break;
273 
274  case COLL_HTML_BITS:
275  nRet = RES_POOLCOLL_STANDARD;
276  break;
277  }
278  }
279 
280  return nRet;
281 }
282 
284 {
285  /* Restore the language independent pool defaults and styles. */
287 
289 
290  pTextFormatColl->ResetFormatAttr( RES_PARATR_ADJUST );
291  /* koreans do not like SvxScriptItem(TRUE) */
292  pTextFormatColl->ResetFormatAttr( RES_PARATR_SCRIPTSPACE );
293 
294  SvxFrameDirectionItem aFrameDir( SvxFrameDirection::Horizontal_LR_TB, RES_FRAMEDIR );
295 
296  size_t nCount = GetPageDescCnt();
297  for( size_t i=0; i<nCount; ++i )
298  {
299  SwPageDesc& rDesc = GetPageDesc( i );
300  rDesc.GetMaster().SetFormatAttr( aFrameDir );
301  rDesc.GetLeft().SetFormatAttr( aFrameDir );
302  }
303 
304  //#i16874# AutoKerning as default for new documents
306 }
307 
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr TypedWhichId< SvxFrameDirectionItem > RES_FRAMEDIR(120)
Subgroup labels.
Definition: poolfmt.hxx:344
bool IsUsed(const sw::BroadcastingModify &) const
Definition: poolfmt.cxx:86
const sal_uInt16 COLL_LISTS_BITS
Definition: poolfmt.hxx:66
const sal_uInt16 COLL_DOC_BITS
Definition: poolfmt.hxx:69
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CTL_FONT(27)
SW_DLLPUBLIC const OUString & GetDefaultListStyleName() const
Definition: list.cxx:251
SwFrameFormat & GetLeft()
Definition: pagedesc.hxx:217
const sal_uInt16 COLL_GET_RANGE_BITS
Definition: poolfmt.hxx:71
std::vector< OUString > m_PatternNames
Definition: doc.hxx:205
Header Left.
Definition: poolfmt.hxx:331
virtual void SetModified()=0
Must be called manually at changes of format.
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_LANGUAGE(10)
Subgroup user indices.
Definition: poolfmt.hxx:381
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_FONTSIZE(8)
const OUString & GetDefaultListId() const
Definition: numrule.hxx:193
Definition: list.hxx:35
const sal_uInt16 COLL_HTML_BITS
Definition: poolfmt.hxx:70
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:150
constexpr TypedWhichId< SvxAutoKernItem > RES_CHRATR_AUTOKERN(17)
const OUString & GetName() const
Definition: numrule.hxx:223
SvxFrameDirection
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CJK_POSTURE(25)
virtual bool GetInfo(SfxPoolItem &) const override
Definition: calbck.cxx:160
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_FONT(7)
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_CTL_LANGUAGE(29)
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:426
Subgroup header.
Definition: poolfmt.hxx:329
void SetAllScriptItem(SfxItemSet &rSet, const SfxPoolItem &rItem)
Definition: poolfmt.cxx:41
int nCount
const OUString & GetTableStyleName() const
Return the table style name of this table.
Definition: swtable.hxx:190
Text body indent.
Definition: poolfmt.hxx:253
const sal_uInt16 COLL_REGISTER_BITS
Definition: poolfmt.hxx:68
const sal_uInt16 POOLGRP_NOCOLLID
POOLCOLL-IDs: +-—+—+—+—+—+—+—+—+—+—+—+—+—+—+—+—+ !User! Range ! 0 ! Offset ! +-—+—+...
Definition: poolfmt.hxx:59
Other stuff.
Definition: poolfmt.hxx:351
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_WEIGHT(15)
object index.
Definition: poolfmt.hxx:399
Table of Contents - heading.
Definition: poolfmt.hxx:341
static SwTable * FindTable(SwFrameFormat const *const pFormat)
Definition: swtable.cxx:1906
Style of a layout element.
Definition: frmfmt.hxx:58
static bool isRightToLeft(LanguageType nLang)
Complimentary close.
Definition: poolfmt.hxx:254
int i
size_t SetDocPattern(const OUString &rPatternName)
Definition: poolfmt.cxx:132
Subgroup headings.
Definition: poolfmt.hxx:260
Subgroup footer.
Definition: poolfmt.hxx:335
const SwPageDesc & GetPageDesc(const size_t i) const
Definition: doc.hxx:883
Text body.
Definition: poolfmt.hxx:250
size_t GetPageDescCnt() const
Definition: doc.hxx:882
Header Left&Right.
Definition: poolfmt.hxx:330
const sal_uInt16 POOLGRP_PAGEDESC
Definition: poolfmt.hxx:77
Header Right.
Definition: poolfmt.hxx:332
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:394
Label drawing objects.
Definition: poolfmt.hxx:357
const OUString * GetDocPattern(size_t nPos) const
Definition: poolfmt.cxx:123
std::unique_ptr< SfxPoolItem > CloneSetWhich(sal_uInt16 nNewWhich) const
SwNumRule::tParagraphStyleList::size_type GetParagraphStyleListSize() const
Definition: number.cxx:1042
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:111
Text body first line indent.
Definition: poolfmt.hxx:251
const sal_uInt16 POOLGRP_FRAMEFMT
Definition: poolfmt.hxx:76
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:449
bool HasNodes() const
Definition: list.cxx:241
const OUString & GetName() const
Definition: tblafmt.hxx:208
illustrations index.
Definition: poolfmt.hxx:395
constexpr TypedWhichId< SvxScriptSpaceItem > RES_PARATR_SCRIPTSPACE(73)
SwFrameFormat & GetMaster()
Definition: pagedesc.hxx:216
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SwNumRule::tTextNodeList::size_type GetTextNodeListSize() const
Definition: number.cxx:128
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CJK_WEIGHT(26)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CTL_WEIGHT(31)
void ResetPoolDefaultItem(sal_uInt16 nWhich)
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:254
Marginalia.
Definition: poolfmt.hxx:257
const sal_uInt16 POOLGRP_NUMRULE
Definition: poolfmt.hxx:78
SwNodes & GetNodes()
Definition: doc.hxx:408
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CJK_FONT(22)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CTL_POSTURE(30)
bool IsUsedByRedline() const
Definition: numrule.hxx:245
Label illustration.
Definition: poolfmt.hxx:345
size_t GetTableFrameFormatCount(bool bUsed) const
Definition: docfmt.cxx:758
tables index.
Definition: poolfmt.hxx:403
virtual bool ResetFormatAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0) override
Definition: fmtcol.cxx:376
SwFrameFormat & GetTableFrameFormat(size_t nFormat, bool bUsed) const
Definition: docfmt.cxx:775
SvxFrameDirection GetDefaultFrameDirection(LanguageType nLanguage)
Return the AutoCollection by its Id.
Definition: poolfmt.cxx:79
void RemoveAllFormatLanguageDependencies()
Definition: poolfmt.cxx:283
Footer Left.
Definition: poolfmt.hxx:336
Subgroup index tables.
Definition: poolfmt.hxx:366
Text body hanging indent.
Definition: poolfmt.hxx:252
Subgroup table of contents.
Definition: poolfmt.hxx:373
const sal_uInt16 COLL_TEXT_BITS
Definition: poolfmt.hxx:65
Subgroup table.
Definition: poolfmt.hxx:340
index of authorities.
Definition: poolfmt.hxx:407
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CTL_FONTSIZE(28)
IDocumentListsAccess const & getIDocumentListsAccess() const
Definition: doc.cxx:293
const sal_uInt16 POOLGRP_CHARFMT
Other groups:
Definition: poolfmt.hxx:75
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CJK_FONTSIZE(23)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_POSTURE(11)
Footer Right.
Definition: poolfmt.hxx:337
sal_uInt16 Which() const
constexpr TypedWhichId< SvxAdjustItem > RES_PARATR_ADJUST(64)
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_CJK_LANGUAGE(24)
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1321
const sal_uInt16 COLL_EXTRA_BITS
Definition: poolfmt.hxx:67