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 <poolfmt.hxx>
29 #include <pagedesc.hxx>
30 #include <fmtcol.hxx>
31 #include <numrule.hxx>
32 #include <swtable.hxx>
33 #include <tblafmt.hxx>
34 #include <hints.hxx>
35 
36 using namespace ::editeng;
37 using namespace ::com::sun::star;
38 
39 void SetAllScriptItem( SfxItemSet& rSet, const SfxPoolItem& rItem )
40 {
41  rSet.Put( rItem );
42  sal_uInt16 nWhCJK = 0, nWhCTL = 0;
43  switch( rItem.Which() )
44  {
46  nWhCJK = RES_CHRATR_CJK_FONTSIZE;
47  nWhCTL = RES_CHRATR_CTL_FONTSIZE;
48  break;
49  case RES_CHRATR_FONT:
50  nWhCJK = RES_CHRATR_CJK_FONT;
51  nWhCTL = RES_CHRATR_CTL_FONT;
52  break;
54  nWhCJK = RES_CHRATR_CJK_LANGUAGE;
55  nWhCTL = RES_CHRATR_CTL_LANGUAGE;
56  break;
57  case RES_CHRATR_POSTURE:
58  nWhCJK = RES_CHRATR_CJK_POSTURE;
59  nWhCTL = RES_CHRATR_CTL_POSTURE;
60  break;
61  case RES_CHRATR_WEIGHT:
62  nWhCJK = RES_CHRATR_CJK_WEIGHT;
63  nWhCTL = RES_CHRATR_CTL_WEIGHT;
64  break;
65  }
66 
67  if( nWhCJK )
68  rSet.Put( rItem.CloneSetWhich(nWhCJK) );
69  if( nWhCTL )
70  rSet.Put( rItem.CloneSetWhich(nWhCTL) );
71 }
72 
78 {
79  return MsLangId::isRightToLeft(nLanguage) ?
80  SvxFrameDirection::Horizontal_RL_TB : SvxFrameDirection::Horizontal_LR_TB;
81 }
82 
83 // See if the Paragraph/Character/Frame/Page style is in use
84 bool SwDoc::IsUsed( const SwModify& rModify ) const
85 {
86  // Check if we have dependent ContentNodes in the Nodes array
87  // (also indirect ones for derived Formats)
88  SwAutoFormatGetDocNode aGetHt( &GetNodes() );
89  return !rModify.GetInfo( aGetHt );
90 }
91 
92 // See if Table style is in use
93 bool SwDoc::IsUsed( const SwTableAutoFormat& rTableAutoFormat) const
94 {
95  size_t nTableCount = GetTableFrameFormatCount(true);
96  for (size_t i=0; i < nTableCount; ++i)
97  {
98  SwFrameFormat* pFrameFormat = &GetTableFrameFormat(i, true);
99  SwTable* pTable = SwTable::FindTable(pFrameFormat);
100  if (pTable->GetTableStyleName() == rTableAutoFormat.GetName())
101  return true;
102  }
103  return false;
104 }
105 
106 // See if the NumRule is used
107 bool SwDoc::IsUsed( const SwNumRule& rRule )
108 {
109  bool bUsed = rRule.GetTextNodeListSize() > 0 ||
110  rRule.GetParagraphStyleListSize() > 0 ||
111  rRule.IsUsedByRedline();
112 
113  return bUsed;
114 }
115 
116 const OUString* SwDoc::GetDocPattern(size_t const nPos) const
117 {
118  if (nPos >= m_PatternNames.size())
119  return nullptr;
120  return &m_PatternNames[nPos];
121 }
122 
123 // Look for the style name's position. If it doesn't exist,
124 // insert an anew
125 size_t SwDoc::SetDocPattern(const OUString& rPatternName)
126 {
127  OSL_ENSURE( !rPatternName.isEmpty(), "no Document style name" );
128 
129  auto const iter(
130  std::find(m_PatternNames.begin(), m_PatternNames.end(), rPatternName));
131  if (iter != m_PatternNames.end())
132  {
133  return std::distance(m_PatternNames.begin(), iter);
134  }
135  else
136  {
137  m_PatternNames.push_back(rPatternName);
139  return m_PatternNames.size() - 1;
140  }
141 }
142 
143 sal_uInt16 GetPoolParent( sal_uInt16 nId )
144 {
145  sal_uInt16 nRet = USHRT_MAX;
146  if( POOLGRP_NOCOLLID & nId ) // 1 == Formats / 0 == Collections
147  {
148  switch( ( COLL_GET_RANGE_BITS | POOLGRP_NOCOLLID ) & nId )
149  {
150  case POOLGRP_CHARFMT:
151  case POOLGRP_FRAMEFMT:
152  nRet = 0; // derived from the default
153  break;
154  case POOLGRP_PAGEDESC:
155  case POOLGRP_NUMRULE:
156  break; // there are no derivations
157  }
158  }
159  else
160  {
161  switch( COLL_GET_RANGE_BITS & nId )
162  {
163  case COLL_TEXT_BITS:
164  switch( nId )
165  {
167  nRet = 0; break;
173  nRet = RES_POOLCOLL_TEXT; break;
174 
175  case RES_POOLCOLL_TEXT:
179  nRet = RES_POOLCOLL_STANDARD; break;
180 
191  nRet = RES_POOLCOLL_HEADLINE_BASE; break;
192  }
193  break;
194 
195  case COLL_LISTS_BITS:
196  switch( nId )
197  {
199  nRet = RES_POOLCOLL_TEXT; break;
200 
201  default:
202  nRet = RES_POOLCOLL_NUMBUL_BASE; break;
203  }
204  break;
205 
206  case COLL_EXTRA_BITS:
207  switch( nId )
208  {
210  nRet = RES_POOLCOLL_TABLE; break;
211 
212  case RES_POOLCOLL_FRAME:
213  case RES_POOLCOLL_TABLE:
219  case RES_POOLCOLL_LABEL:
220  nRet = RES_POOLCOLL_STANDARD; break;
221  case RES_POOLCOLL_HEADER:
222  nRet = RES_POOLCOLL_HEADERFOOTER; break;
225  nRet = RES_POOLCOLL_HEADER; break;
226  case RES_POOLCOLL_FOOTER:
227  nRet = RES_POOLCOLL_HEADERFOOTER; break;
230  nRet = RES_POOLCOLL_FOOTER; break;
231 
237  nRet = RES_POOLCOLL_LABEL; break;
238  }
239  break;
240 
241  case COLL_REGISTER_BITS:
242  switch( nId )
243  {
245  nRet = RES_POOLCOLL_STANDARD; break;
246 
248  nRet = RES_POOLCOLL_HEADLINE_BASE; break;
249 
256  nRet = RES_POOLCOLL_TOX_IDXH; break;
257 
258  default:
259  nRet = RES_POOLCOLL_REGISTER_BASE; break;
260  }
261  break;
262 
263  case COLL_DOC_BITS:
265  break;
266 
267  case COLL_HTML_BITS:
268  nRet = RES_POOLCOLL_STANDARD;
269  break;
270  }
271  }
272 
273  return nRet;
274 }
275 
277 {
278  /* Restore the language independent pool defaults and styles. */
280 
282 
283  pTextFormatColl->ResetFormatAttr( RES_PARATR_ADJUST );
284  /* koreans do not like SvxScriptItem(TRUE) */
285  pTextFormatColl->ResetFormatAttr( RES_PARATR_SCRIPTSPACE );
286 
287  SvxFrameDirectionItem aFrameDir( SvxFrameDirection::Horizontal_LR_TB, RES_FRAMEDIR );
288 
289  size_t nCount = GetPageDescCnt();
290  for( size_t i=0; i<nCount; ++i )
291  {
292  SwPageDesc& rDesc = GetPageDesc( i );
293  rDesc.GetMaster().SetFormatAttr( aFrameDir );
294  rDesc.GetLeft().SetFormatAttr( aFrameDir );
295  }
296 
297  //#i16874# AutoKerning as default for new documents
299 }
300 
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Subgroup labels.
Definition: poolfmt.hxx:345
#define RES_CHRATR_WEIGHT
Definition: hintids.hxx:84
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:93
SwFrameFormat & GetLeft()
Definition: pagedesc.hxx:218
#define RES_CHRATR_FONTSIZE
Definition: hintids.hxx:77
#define RES_CHRATR_LANGUAGE
Definition: hintids.hxx:79
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:94
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:227
const sal_uInt16 COLL_HTML_BITS
Definition: poolfmt.hxx:71
#define RES_CHRATR_CJK_WEIGHT
Definition: hintids.hxx:95
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:143
#define RES_CHRATR_FONT
Definition: hintids.hxx:76
SvxFrameDirection
#define RES_CHRATR_CJK_FONT
Definition: hintids.hxx:91
#define RES_CHRATR_CJK_FONTSIZE
Definition: hintids.hxx:92
virtual bool GetInfo(SfxPoolItem &) const override
Definition: calbck.cxx:206
#define RES_CHRATR_CTL_FONTSIZE
Definition: hintids.hxx:97
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:425
Subgroup header.
Definition: poolfmt.hxx:330
void SetAllScriptItem(SfxItemSet &rSet, const SfxPoolItem &rItem)
Definition: poolfmt.cxx:39
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:96
size_t SetDocPattern(const OUString &rPatternName)
Definition: poolfmt.cxx:125
Subgroup headings.
Definition: poolfmt.hxx:261
Subgroup footer.
Definition: poolfmt.hxx:336
const SwPageDesc & GetPageDesc(const size_t i) const
Definition: doc.hxx:877
Text body.
Definition: poolfmt.hxx:251
int i
#define RES_PARATR_SCRIPTSPACE
Definition: hintids.hxx:172
size_t GetPageDescCnt() const
Definition: doc.hxx:876
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:393
Label drawing objects.
Definition: poolfmt.hxx:358
const OUString * GetDocPattern(size_t nPos) const
Definition: poolfmt.cxx:116
std::unique_ptr< SfxPoolItem > CloneSetWhich(sal_uInt16 nNewWhich) const
SwNumRule::tParagraphStyleList::size_type GetParagraphStyleListSize() const
Definition: number.cxx:987
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:458
const OUString & GetName() const
Definition: tblafmt.hxx:208
illustrations index.
Definition: poolfmt.hxx:396
SwFrameFormat & GetMaster()
Definition: pagedesc.hxx:217
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SwNumRule::tTextNodeList::size_type GetTextNodeListSize() const
Definition: number.cxx:126
#define RES_CHRATR_CTL_LANGUAGE
Definition: hintids.hxx:98
#define RES_CHRATR_POSTURE
Definition: hintids.hxx:80
#define RES_CHRATR_CTL_WEIGHT
Definition: hintids.hxx:100
#define RES_CHRATR_CTL_POSTURE
Definition: hintids.hxx:99
void ResetPoolDefaultItem(sal_uInt16 nWhich)
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
Marginalia.
Definition: poolfmt.hxx:258
const sal_uInt16 POOLGRP_NUMRULE
Definition: poolfmt.hxx:79
bool IsUsed(const SwModify &) const
Definition: poolfmt.cxx:84
SwNodes & GetNodes()
Definition: doc.hxx:402
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
bool IsUsedByRedline() const
Definition: numrule.hxx:243
#define RES_PARATR_ADJUST
Definition: hintids.hxx:163
Label illustration.
Definition: poolfmt.hxx:346
size_t GetTableFrameFormatCount(bool bUsed) const
Definition: docfmt.cxx:750
tables index.
Definition: poolfmt.hxx:404
virtual bool ResetFormatAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0) override
Definition: fmtcol.cxx:366
SwFrameFormat & GetTableFrameFormat(size_t nFormat, bool bUsed) const
Definition: docfmt.cxx:767
SvxFrameDirection GetDefaultFrameDirection(LanguageType nLanguage)
Return the AutoCollection by its Id.
Definition: poolfmt.cxx:77
void RemoveAllFormatLanguageDependencies()
Definition: poolfmt.cxx:276
#define RES_CHRATR_AUTOKERN
Definition: hintids.hxx:86
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:1309
const sal_uInt16 COLL_EXTRA_BITS
Definition: poolfmt.hxx:68