1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <hintids.hxx>
21 #include <i18nlangtag/mslangid.hxx>
22 #include <editeng/boxitem.hxx>
23 #include <editeng/frmdiritem.hxx>
24 #include <osl/diagnose.h>
26 #include <IDocumentState.hxx>
27 #include <IDocumentStylePoolAccess.hxx>
28 #include <IDocumentListsAccess.hxx>
30 #include <poolfmt.hxx>
31 #include <pagedesc.hxx>
33 #include <numrule.hxx>
34 #include <swtable.hxx>
35 #include <tblafmt.hxx>
38 using namespace ::editeng
;
39 using namespace ::com::sun::star
;
41 void SetAllScriptItem( SfxItemSet
& rSet
, const SfxPoolItem
& rItem
)
44 sal_uInt16 nWhCJK
= 0, nWhCTL
= 0;
45 switch( rItem
.Which() )
47 case RES_CHRATR_FONTSIZE
:
48 nWhCJK
= RES_CHRATR_CJK_FONTSIZE
;
49 nWhCTL
= RES_CHRATR_CTL_FONTSIZE
;
52 nWhCJK
= RES_CHRATR_CJK_FONT
;
53 nWhCTL
= RES_CHRATR_CTL_FONT
;
55 case RES_CHRATR_LANGUAGE
:
56 nWhCJK
= RES_CHRATR_CJK_LANGUAGE
;
57 nWhCTL
= RES_CHRATR_CTL_LANGUAGE
;
59 case RES_CHRATR_POSTURE
:
60 nWhCJK
= RES_CHRATR_CJK_POSTURE
;
61 nWhCTL
= RES_CHRATR_CTL_POSTURE
;
63 case RES_CHRATR_WEIGHT
:
64 nWhCJK
= RES_CHRATR_CJK_WEIGHT
;
65 nWhCTL
= RES_CHRATR_CTL_WEIGHT
;
70 rSet
.Put( rItem
.CloneSetWhich(nWhCJK
) );
72 rSet
.Put( rItem
.CloneSetWhich(nWhCTL
) );
75 /// Return the AutoCollection by its Id. If it doesn't
76 /// exist yet, create it.
77 /// If the String pointer is defined, then only query for
78 /// the Attribute descriptions. It doesn't create a style!
79 SvxFrameDirection
GetDefaultFrameDirection(LanguageType nLanguage
)
81 return MsLangId::isRightToLeft(nLanguage
) ?
82 SvxFrameDirection::Horizontal_RL_TB
: SvxFrameDirection::Horizontal_LR_TB
;
85 // See if the Paragraph/Character/Frame/Page style is in use
86 bool SwDoc::IsUsed( const sw::BroadcastingModify
& rModify
) const
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
);
94 // See if Table style is in use
95 bool SwDoc::IsUsed( const SwTableAutoFormat
& rTableAutoFormat
) const
97 size_t nTableCount
= GetTableFrameFormatCount(true);
98 for (size_t i
=0; i
< nTableCount
; ++i
)
100 SwFrameFormat
* pFrameFormat
= &GetTableFrameFormat(i
, true);
101 SwTable
* pTable
= SwTable::FindTable(pFrameFormat
);
102 if (pTable
->GetTableStyleName() == rTableAutoFormat
.GetName())
108 // See if the NumRule is used
109 bool SwDoc::IsUsed( const SwNumRule
& rRule
) const
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
117 && pList
->GetDefaultListStyleName() == rRule
.GetName()
118 && pList
->HasNodes());
123 const OUString
* SwDoc::GetDocPattern(size_t const nPos
) const
125 if (nPos
>= m_PatternNames
.size())
127 return &m_PatternNames
[nPos
];
130 // Look for the style name's position. If it doesn't exist,
132 size_t SwDoc::SetDocPattern(const OUString
& rPatternName
)
134 OSL_ENSURE( !rPatternName
.isEmpty(), "no Document style name" );
137 std::find(m_PatternNames
.begin(), m_PatternNames
.end(), rPatternName
));
138 if (iter
!= m_PatternNames
.end())
140 return std::distance(m_PatternNames
.begin(), iter
);
144 m_PatternNames
.push_back(rPatternName
);
145 getIDocumentState().SetModified();
146 return m_PatternNames
.size() - 1;
150 sal_uInt16
GetPoolParent( sal_uInt16 nId
)
152 sal_uInt16 nRet
= USHRT_MAX
;
153 if( POOLGRP_NOCOLLID
& nId
) // 1 == Formats / 0 == Collections
155 switch( ( COLL_GET_RANGE_BITS
| POOLGRP_NOCOLLID
) & nId
)
157 case POOLGRP_CHARFMT
:
158 case POOLGRP_FRAMEFMT
:
159 nRet
= 0; // derived from the default
161 case POOLGRP_PAGEDESC
:
162 case POOLGRP_NUMRULE
:
163 break; // there are no derivations
168 switch( COLL_GET_RANGE_BITS
& nId
)
173 case RES_POOLCOLL_STANDARD
:
175 case RES_POOLCOLL_TEXT_IDENT
:
176 case RES_POOLCOLL_TEXT_NEGIDENT
:
177 case RES_POOLCOLL_TEXT_MOVE
:
178 case RES_POOLCOLL_CONFRONTATION
:
179 case RES_POOLCOLL_MARGINAL
:
180 nRet
= RES_POOLCOLL_TEXT
; break;
182 case RES_POOLCOLL_TEXT
:
183 case RES_POOLCOLL_GREETING
:
184 case RES_POOLCOLL_SIGNATURE
:
185 case RES_POOLCOLL_HEADLINE_BASE
:
186 nRet
= RES_POOLCOLL_STANDARD
; break;
188 case RES_POOLCOLL_HEADLINE1
:
189 case RES_POOLCOLL_HEADLINE2
:
190 case RES_POOLCOLL_HEADLINE3
:
191 case RES_POOLCOLL_HEADLINE4
:
192 case RES_POOLCOLL_HEADLINE5
:
193 case RES_POOLCOLL_HEADLINE6
:
194 case RES_POOLCOLL_HEADLINE7
:
195 case RES_POOLCOLL_HEADLINE8
:
196 case RES_POOLCOLL_HEADLINE9
:
197 case RES_POOLCOLL_HEADLINE10
:
198 nRet
= RES_POOLCOLL_HEADLINE_BASE
; break;
202 case COLL_LISTS_BITS
:
205 case RES_POOLCOLL_NUMBER_BULLET_BASE
:
206 nRet
= RES_POOLCOLL_TEXT
; break;
209 nRet
= RES_POOLCOLL_NUMBER_BULLET_BASE
; break;
213 case COLL_EXTRA_BITS
:
216 case RES_POOLCOLL_TABLE_HDLN
:
217 nRet
= RES_POOLCOLL_TABLE
; break;
219 case RES_POOLCOLL_FRAME
:
220 case RES_POOLCOLL_TABLE
:
221 case RES_POOLCOLL_FOOTNOTE
:
222 case RES_POOLCOLL_ENDNOTE
:
223 case RES_POOLCOLL_ENVELOPE_ADDRESS
:
224 case RES_POOLCOLL_SEND_ADDRESS
:
225 case RES_POOLCOLL_HEADERFOOTER
:
226 case RES_POOLCOLL_LABEL
:
227 nRet
= RES_POOLCOLL_STANDARD
; break;
228 case RES_POOLCOLL_HEADER
:
229 nRet
= RES_POOLCOLL_HEADERFOOTER
; break;
230 case RES_POOLCOLL_HEADERL
:
231 case RES_POOLCOLL_HEADERR
:
232 nRet
= RES_POOLCOLL_HEADER
; break;
233 case RES_POOLCOLL_FOOTER
:
234 nRet
= RES_POOLCOLL_HEADERFOOTER
; break;
235 case RES_POOLCOLL_FOOTERL
:
236 case RES_POOLCOLL_FOOTERR
:
237 nRet
= RES_POOLCOLL_FOOTER
; break;
239 case RES_POOLCOLL_LABEL_ABB
:
240 case RES_POOLCOLL_LABEL_TABLE
:
241 case RES_POOLCOLL_LABEL_FRAME
:
242 case RES_POOLCOLL_LABEL_DRAWING
:
243 case RES_POOLCOLL_LABEL_FIGURE
:
244 nRet
= RES_POOLCOLL_LABEL
; break;
248 case COLL_REGISTER_BITS
:
251 case RES_POOLCOLL_REGISTER_BASE
:
252 nRet
= RES_POOLCOLL_STANDARD
; break;
254 case RES_POOLCOLL_TOX_IDXH
:
255 nRet
= RES_POOLCOLL_HEADLINE_BASE
; break;
257 case RES_POOLCOLL_TOX_USERH
:
258 case RES_POOLCOLL_TOX_CNTNTH
:
259 case RES_POOLCOLL_TOX_ILLUSH
:
260 case RES_POOLCOLL_TOX_OBJECTH
:
261 case RES_POOLCOLL_TOX_TABLESH
:
262 case RES_POOLCOLL_TOX_AUTHORITIESH
:
263 nRet
= RES_POOLCOLL_TOX_IDXH
; break;
266 nRet
= RES_POOLCOLL_REGISTER_BASE
; break;
271 nRet
= RES_POOLCOLL_HEADLINE_BASE
;
275 nRet
= RES_POOLCOLL_STANDARD
;
283 void SwDoc::RemoveAllFormatLanguageDependencies()
285 /* Restore the language independent pool defaults and styles. */
286 GetAttrPool().ResetPoolDefaultItem( RES_PARATR_ADJUST
);
288 SwTextFormatColl
* pTextFormatColl
= getIDocumentStylePoolAccess().GetTextCollFromPool( RES_POOLCOLL_STANDARD
);
290 pTextFormatColl
->ResetFormatAttr( RES_PARATR_ADJUST
);
291 /* koreans do not like SvxScriptItem(TRUE) */
292 pTextFormatColl
->ResetFormatAttr( RES_PARATR_SCRIPTSPACE
);
294 SvxFrameDirectionItem
aFrameDir( SvxFrameDirection::Horizontal_LR_TB
, RES_FRAMEDIR
);
296 size_t nCount
= GetPageDescCnt();
297 for( size_t i
=0; i
<nCount
; ++i
)
299 SwPageDesc
& rDesc
= GetPageDesc( i
);
300 rDesc
.GetMaster().SetFormatAttr( aFrameDir
);
301 rDesc
.GetLeft().SetFormatAttr( aFrameDir
);
304 //#i16874# AutoKerning as default for new documents
305 GetAttrPool().ResetPoolDefaultItem( RES_CHRATR_AUTOKERN
);
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */