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>
22#include <editeng/boxitem.hxx>
24#include <osl/diagnose.h>
25#include <doc.hxx>
26#include <IDocumentState.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
38using namespace ::editeng;
39using namespace ::com::sun::star;
40
41void SetAllScriptItem( SfxItemSet& rSet, const SfxPoolItem& rItem )
42{
43 rSet.Put( rItem );
44 sal_uInt16 nWhCJK = 0, nWhCTL = 0;
45 switch( rItem.Which() )
46 {
50 break;
51 case RES_CHRATR_FONT:
52 nWhCJK = RES_CHRATR_CJK_FONT;
53 nWhCTL = RES_CHRATR_CTL_FONT;
54 break;
58 break;
62 break;
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
86bool 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)
91 return !rModify.GetInfo( aGetHt );
92}
93
94// See if Table style is in use
95bool 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
109bool SwDoc::IsUsed( const SwNumRule& rRule ) const
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
123const 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
132size_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
150sal_uInt16 GetPoolParent( sal_uInt16 nId )
151{
152 sal_uInt16 nRet = USHRT_MAX;
153 if( POOLGRP_NOCOLLID & nId ) // 1 == Formats / 0 == Collections
154 {
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
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:
210 }
211 break;
212
213 case COLL_EXTRA_BITS:
214 switch( nId )
215 {
217 nRet = RES_POOLCOLL_TABLE; break;
218
228 nRet = RES_POOLCOLL_STANDARD; break;
230 nRet = RES_POOLCOLL_HEADERFOOTER; break;
233 nRet = RES_POOLCOLL_HEADER; break;
235 nRet = RES_POOLCOLL_HEADERFOOTER; break;
238 nRet = RES_POOLCOLL_FOOTER; break;
239
245 nRet = RES_POOLCOLL_LABEL; break;
246 }
247 break;
248
250 switch( nId )
251 {
253 nRet = RES_POOLCOLL_STANDARD; break;
254
256 nRet = RES_POOLCOLL_HEADLINE_BASE; break;
257
264 nRet = RES_POOLCOLL_TOX_IDXH; break;
265
266 default:
267 nRet = RES_POOLCOLL_REGISTER_BASE; break;
268 }
269 break;
270
271 case COLL_DOC_BITS:
273 break;
274
275 case COLL_HTML_BITS:
277 break;
278 }
279 }
280
281 return nRet;
282}
283
285{
286 /* Restore the language independent pool defaults and styles. */
288
290
291 pTextFormatColl->ResetFormatAttr( RES_PARATR_ADJUST );
292 /* koreans do not like SvxScriptItem(TRUE) */
293 pTextFormatColl->ResetFormatAttr( RES_PARATR_SCRIPTSPACE );
294
295 SvxFrameDirectionItem aFrameDir( SvxFrameDirection::Horizontal_LR_TB, RES_FRAMEDIR );
296
297 size_t nCount = GetPageDescCnt();
298 for( size_t i=0; i<nCount; ++i )
299 {
300 SwPageDesc& rDesc = GetPageDesc( i );
301 rDesc.GetMaster().SetFormatAttr( aFrameDir );
302 rDesc.GetLeft().SetFormatAttr( aFrameDir );
303 }
304
305 //#i16874# AutoKerning as default for new documents
307}
308
309/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetModified()=0
Must be called manually at changes of format.
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
static bool isRightToLeft(LanguageType nLang)
void ResetPoolDefaultItem(sal_uInt16 nWhich)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 Which() const
std::unique_ptr< SfxPoolItem > CloneSetWhich(sal_uInt16 nNewWhich) const
const OUString * GetDocPattern(size_t nPos) const
Definition: poolfmt.cxx:123
size_t GetTableFrameFormatCount(bool bUsed) const
Definition: docfmt.cxx:778
size_t SetDocPattern(const OUString &rPatternName)
Definition: poolfmt.cxx:132
std::vector< OUString > m_PatternNames
Definition: doc.hxx:214
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:408
bool IsUsed(const sw::BroadcastingModify &) const
Definition: poolfmt.cxx:86
void RemoveAllFormatLanguageDependencies()
Definition: poolfmt.cxx:284
size_t GetPageDescCnt() const
Definition: doc.hxx:895
SwNodes & GetNodes()
Definition: doc.hxx:422
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:440
SwTableFormat & GetTableFrameFormat(size_t nFormat, bool bUsed) const
Definition: docfmt.cxx:795
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1337
const SwPageDesc & GetPageDesc(const size_t i) const
Definition: doc.hxx:896
IDocumentListsAccess const & getIDocumentListsAccess() const
Definition: doc.cxx:307
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:447
Style of a layout element.
Definition: frmfmt.hxx:72
Definition: list.hxx:40
bool HasNodes() const
Definition: list.cxx:77
const OUString & GetDefaultListStyleName() const
Definition: list.hxx:49
SwNumRule::tParagraphStyleList::size_type GetParagraphStyleListSize() const
Definition: number.cxx:1093
bool IsUsedByRedline() const
Definition: numrule.hxx:246
SwNumRule::tTextNodeList::size_type GetTextNodeListSize() const
Definition: number.cxx:136
const OUString & GetDefaultListId() const
Definition: numrule.hxx:194
const OUString & GetName() const
Definition: numrule.hxx:224
SwFrameFormat & GetMaster()
Definition: pagedesc.hxx:238
SwFrameFormat & GetLeft()
Definition: pagedesc.hxx:239
const OUString & GetName() const
Definition: tblafmt.hxx:206
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:113
const OUString & GetTableStyleName() const
Return the table style name of this table.
Definition: swtable.hxx:196
static SwTable * FindTable(SwFrameFormat const *const pFormat)
Definition: swtable.cxx:2308
Represents the style of a paragraph.
Definition: fmtcol.hxx:61
virtual bool ResetFormatAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0) override
Definition: fmtcol.cxx:432
int nCount
SvxFrameDirection
constexpr TypedWhichId< SvxFrameDirectionItem > RES_FRAMEDIR(126)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CTL_FONTSIZE(28)
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CJK_FONT(22)
constexpr TypedWhichId< SvxAutoKernItem > RES_CHRATR_AUTOKERN(17)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_FONTSIZE(8)
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_LANGUAGE(10)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_WEIGHT(15)
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_CTL_LANGUAGE(29)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CJK_FONTSIZE(23)
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CTL_FONT(27)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CTL_WEIGHT(31)
constexpr TypedWhichId< SvxAdjustItem > RES_PARATR_ADJUST(64)
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_CJK_LANGUAGE(24)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CTL_POSTURE(30)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_POSTURE(11)
constexpr TypedWhichId< SvxScriptSpaceItem > RES_PARATR_SCRIPTSPACE(73)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CJK_WEIGHT(26)
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_FONT(7)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CJK_POSTURE(25)
sal_uInt16 nPos
int i
sal_Int16 nId
void SetAllScriptItem(SfxItemSet &rSet, const SfxPoolItem &rItem)
Definition: poolfmt.cxx:41
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
SvxFrameDirection GetDefaultFrameDirection(LanguageType nLanguage)
Return the AutoCollection by its Id.
Definition: poolfmt.cxx:79
const sal_uInt16 COLL_DOC_BITS
Definition: poolfmt.hxx:69
@ RES_POOLCOLL_LABEL_DRAWING
Label drawing objects.
Definition: poolfmt.hxx:358
@ RES_POOLCOLL_HEADLINE5
Heading 5.
Definition: poolfmt.hxx:266
@ RES_POOLCOLL_TEXT
Text body.
Definition: poolfmt.hxx:251
@ RES_POOLCOLL_STANDARD
Standard.
Definition: poolfmt.hxx:250
@ RES_POOLCOLL_GREETING
Complimentary close.
Definition: poolfmt.hxx:255
@ RES_POOLCOLL_HEADLINE6
Heading 6.
Definition: poolfmt.hxx:267
@ RES_POOLCOLL_HEADERFOOTER
Subgroup header.
Definition: poolfmt.hxx:330
@ RES_POOLCOLL_HEADLINE10
Heading 10.
Definition: poolfmt.hxx:271
@ RES_POOLCOLL_SIGNATURE
Signature.
Definition: poolfmt.hxx:256
@ RES_POOLCOLL_TOX_USERH
Subgroup user indices.
Definition: poolfmt.hxx:384
@ RES_POOLCOLL_REGISTER_BASE
Base index.
Definition: poolfmt.hxx:366
@ RES_POOLCOLL_MARGINAL
Marginalia.
Definition: poolfmt.hxx:258
@ RES_POOLCOLL_TOX_CNTNTH
Subgroup table of contents.
Definition: poolfmt.hxx:376
@ RES_POOLCOLL_LABEL
Subgroup labels.
Definition: poolfmt.hxx:345
@ RES_POOLCOLL_TOX_TABLESH
tables index.
Definition: poolfmt.hxx:406
@ RES_POOLCOLL_TEXT_NEGIDENT
Text body hanging indent.
Definition: poolfmt.hxx:253
@ RES_POOLCOLL_NUMBER_BULLET_BASE
Base list.
Definition: poolfmt.hxx:278
@ RES_POOLCOLL_LABEL_FRAME
Label frame.
Definition: poolfmt.hxx:348
@ RES_POOLCOLL_TOX_IDXH
Subgroup index tables.
Definition: poolfmt.hxx:369
@ RES_POOLCOLL_LABEL_FIGURE
Label figure.
Definition: poolfmt.hxx:349
@ RES_POOLCOLL_HEADLINE8
Heading 8.
Definition: poolfmt.hxx:269
@ RES_POOLCOLL_TOX_OBJECTH
object index.
Definition: poolfmt.hxx:402
@ RES_POOLCOLL_ENVELOPE_ADDRESS
Addressee.
Definition: poolfmt.hxx:354
@ RES_POOLCOLL_TABLE
Subgroup table.
Definition: poolfmt.hxx:341
@ RES_POOLCOLL_COMMENT
Comment.
Definition: poolfmt.hxx:359
@ RES_POOLCOLL_CONFRONTATION
List indent.
Definition: poolfmt.hxx:257
@ RES_POOLCOLL_FOOTERR
Footer Right.
Definition: poolfmt.hxx:338
@ RES_POOLCOLL_HEADER
Header Left&Right.
Definition: poolfmt.hxx:331
@ RES_POOLCOLL_TOX_ILLUSH
illustrations index.
Definition: poolfmt.hxx:398
@ RES_POOLCOLL_HEADLINE9
Heading 9.
Definition: poolfmt.hxx:270
@ RES_POOLCOLL_FOOTERL
Footer Left.
Definition: poolfmt.hxx:337
@ RES_POOLCOLL_FRAME
Other stuff.
Definition: poolfmt.hxx:352
@ RES_POOLCOLL_LABEL_TABLE
Label table.
Definition: poolfmt.hxx:347
@ RES_POOLCOLL_LABEL_ABB
Label illustration.
Definition: poolfmt.hxx:346
@ RES_POOLCOLL_TEXT_MOVE
Text body indent.
Definition: poolfmt.hxx:254
@ RES_POOLCOLL_HEADLINE_BASE
Subgroup headings.
Definition: poolfmt.hxx:261
@ RES_POOLCOLL_SEND_ADDRESS
Sender.
Definition: poolfmt.hxx:355
@ RES_POOLCOLL_HEADERL
Header Left.
Definition: poolfmt.hxx:332
@ RES_POOLCOLL_HEADLINE2
Heading 2.
Definition: poolfmt.hxx:263
@ RES_POOLCOLL_HEADLINE4
Heading 4.
Definition: poolfmt.hxx:265
@ RES_POOLCOLL_FOOTNOTE
Footnotes.
Definition: poolfmt.hxx:353
@ RES_POOLCOLL_TOX_AUTHORITIESH
index of authorities.
Definition: poolfmt.hxx:410
@ RES_POOLCOLL_HEADLINE7
Heading 7.
Definition: poolfmt.hxx:268
@ RES_POOLCOLL_HEADLINE1
Heading 1.
Definition: poolfmt.hxx:262
@ RES_POOLCOLL_HEADERR
Header Right.
Definition: poolfmt.hxx:333
@ RES_POOLCOLL_TABLE_HDLN
Table of Contents - heading.
Definition: poolfmt.hxx:342
@ RES_POOLCOLL_FOOTER
Subgroup footer.
Definition: poolfmt.hxx:336
@ RES_POOLCOLL_TEXT_IDENT
Text body first line indent.
Definition: poolfmt.hxx:252
@ RES_POOLCOLL_HEADLINE3
Heading 3.
Definition: poolfmt.hxx:264
@ RES_POOLCOLL_ENDNOTE
Endnotes.
Definition: poolfmt.hxx:356
const sal_uInt16 POOLGRP_FRAMEFMT
Definition: poolfmt.hxx:76
const sal_uInt16 POOLGRP_NOCOLLID
POOLCOLL-IDs: +-—+—+—+—+—+—+—+—+—+—+—+—+—+—+—+—+ !User! Range ! 0 ! Offset ! +-—+—+—+—+—+—+—+—+—+—+—+...
Definition: poolfmt.hxx:59
const sal_uInt16 COLL_GET_RANGE_BITS
Definition: poolfmt.hxx:71
const sal_uInt16 POOLGRP_NUMRULE
Definition: poolfmt.hxx:78
const sal_uInt16 COLL_REGISTER_BITS
Definition: poolfmt.hxx:68
const sal_uInt16 COLL_TEXT_BITS
Definition: poolfmt.hxx:65
const sal_uInt16 POOLGRP_CHARFMT
Other groups:
Definition: poolfmt.hxx:75
const sal_uInt16 POOLGRP_PAGEDESC
Definition: poolfmt.hxx:77
const sal_uInt16 COLL_HTML_BITS
Definition: poolfmt.hxx:70
const sal_uInt16 COLL_LISTS_BITS
Definition: poolfmt.hxx:66
const sal_uInt16 COLL_EXTRA_BITS
Definition: poolfmt.hxx:67
static SfxItemSet & rSet