android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / doc / poolfmt.cxx
bloba7788cd0f56a167a7408a5a2decc96186342053d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include <doc.hxx>
26 #include <IDocumentState.hxx>
27 #include <IDocumentStylePoolAccess.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>
38 using namespace ::editeng;
39 using namespace ::com::sun::star;
41 void SetAllScriptItem( SfxItemSet& rSet, const SfxPoolItem& rItem )
43 rSet.Put( 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;
50 break;
51 case RES_CHRATR_FONT:
52 nWhCJK = RES_CHRATR_CJK_FONT;
53 nWhCTL = RES_CHRATR_CTL_FONT;
54 break;
55 case RES_CHRATR_LANGUAGE:
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;
69 if( nWhCJK )
70 rSet.Put( rItem.CloneSetWhich(nWhCJK) );
71 if( nWhCTL )
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())
103 return true;
105 return false;
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
116 || (pList
117 && pList->GetDefaultListStyleName() == rRule.GetName()
118 && pList->HasNodes());
120 return bUsed;
123 const OUString* SwDoc::GetDocPattern(size_t const nPos) const
125 if (nPos >= m_PatternNames.size())
126 return nullptr;
127 return &m_PatternNames[nPos];
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)
134 OSL_ENSURE( !rPatternName.isEmpty(), "no Document style name" );
136 auto const iter(
137 std::find(m_PatternNames.begin(), m_PatternNames.end(), rPatternName));
138 if (iter != m_PatternNames.end())
140 return std::distance(m_PatternNames.begin(), iter);
142 else
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
160 break;
161 case POOLGRP_PAGEDESC:
162 case POOLGRP_NUMRULE:
163 break; // there are no derivations
166 else
168 switch( COLL_GET_RANGE_BITS & nId )
170 case COLL_TEXT_BITS:
171 switch( nId )
173 case RES_POOLCOLL_STANDARD:
174 nRet = 0; break;
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;
200 break;
202 case COLL_LISTS_BITS:
203 switch( nId )
205 case RES_POOLCOLL_NUMBER_BULLET_BASE:
206 nRet = RES_POOLCOLL_TEXT; break;
208 default:
209 nRet = RES_POOLCOLL_NUMBER_BULLET_BASE; break;
211 break;
213 case COLL_EXTRA_BITS:
214 switch( nId )
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;
246 break;
248 case COLL_REGISTER_BITS:
249 switch( nId )
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;
265 default:
266 nRet = RES_POOLCOLL_REGISTER_BASE; break;
268 break;
270 case COLL_DOC_BITS:
271 nRet = RES_POOLCOLL_HEADLINE_BASE;
272 break;
274 case COLL_HTML_BITS:
275 nRet = RES_POOLCOLL_STANDARD;
276 break;
280 return nRet;
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: */