Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / shells / txtattr.cxx
blobc5c90c8afc7c2b762e320c617d311238b1c2bc0d
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>
22 #include <svl/whiter.hxx>
23 #include <svl/stritem.hxx>
24 #include <svl/ctloptions.hxx>
25 #include <swmodule.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/request.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <editeng/fhgtitem.hxx>
30 #include <editeng/adjustitem.hxx>
31 #include <editeng/lspcitem.hxx>
32 #include <editeng/lrspitem.hxx>
33 #include <editeng/udlnitem.hxx>
34 #include <editeng/escapementitem.hxx>
35 #include <editeng/pmdlitem.hxx>
36 #include <sfx2/htmlmode.hxx>
37 #include <editeng/scripttypeitem.hxx>
38 #include <editeng/frmdiritem.hxx>
39 #include <editeng/cmapitem.hxx>
40 #include <osl/diagnose.h>
41 #include <paratr.hxx>
43 #include <fmtinfmt.hxx>
44 #include <wrtsh.hxx>
45 #include <view.hxx>
46 #include <viewopt.hxx>
47 #include <uitool.hxx>
48 #include <textsh.hxx>
49 #include <swundo.hxx>
50 #include <fmtcol.hxx>
52 #include <cmdid.h>
53 #include <globals.h>
54 #include <SwStyleNameMapper.hxx>
55 #include <swabstdlg.hxx>
56 #include <memory>
58 const sal_uInt32 nFontInc = 40; // 2pt
59 const sal_uInt32 nFontMaxSz = 19998; // 999.9pt
61 void SwTextShell::ExecCharAttr(SfxRequest &rReq)
63 SwWrtShell &rSh = GetShell();
64 const SfxItemSet *pArgs = rReq.GetArgs();
65 int eState = STATE_TOGGLE;
66 sal_uInt16 nWhich = rReq.GetSlot();
68 if(pArgs )
70 const SfxPoolItem* pItem;
71 pArgs->GetItemState(nWhich, false, &pItem);
72 eState = static_cast<const SfxBoolItem &>( pArgs->
73 Get( nWhich )).GetValue() ? STATE_ON : STATE_OFF;
76 SfxItemSetFixed<RES_CHRATR_BEGIN, RES_CHRATR_END-1> aSet( GetPool() );
77 if (STATE_TOGGLE == eState)
78 rSh.GetCurAttr( aSet );
80 switch ( nWhich )
82 case FN_SET_SUB_SCRIPT:
83 case FN_SET_SUPER_SCRIPT:
85 SvxEscapement eEscape = SvxEscapement::Subscript;
86 switch (eState)
88 case STATE_TOGGLE:
90 short nTmpEsc = aSet.Get( RES_CHRATR_ESCAPEMENT ).GetEsc();
91 eEscape = nWhich == FN_SET_SUPER_SCRIPT ?
92 SvxEscapement::Superscript:
93 SvxEscapement::Subscript;
94 if( (nWhich == FN_SET_SUB_SCRIPT && nTmpEsc < 0) ||
95 (nWhich == FN_SET_SUPER_SCRIPT && nTmpEsc > 0) )
96 eEscape = SvxEscapement::Off;
98 SfxBindings& rBind = GetView().GetViewFrame().GetBindings();
99 if( nWhich == FN_SET_SUB_SCRIPT )
100 rBind.SetState( SfxBoolItem( FN_SET_SUPER_SCRIPT,
101 false ) );
102 else
103 rBind.SetState( SfxBoolItem( FN_SET_SUB_SCRIPT,
104 false ) );
107 break;
108 case STATE_ON:
109 eEscape = nWhich == FN_SET_SUPER_SCRIPT ?
110 SvxEscapement::Superscript:
111 SvxEscapement::Subscript;
112 break;
113 case STATE_OFF:
114 eEscape = SvxEscapement::Off;
115 break;
117 SvxEscapementItem aEscape( eEscape, RES_CHRATR_ESCAPEMENT );
118 if(eEscape == SvxEscapement::Superscript)
119 aEscape.GetEsc() = DFLT_ESC_AUTO_SUPER;
120 else if(eEscape == SvxEscapement::Subscript)
121 aEscape.GetEsc() = DFLT_ESC_AUTO_SUB;
122 rSh.SetAttrItem( aEscape );
123 rReq.AppendItem( aEscape );
124 rReq.Done();
126 break;
128 case FN_SET_SMALL_CAPS:
130 SvxCaseMap eCaseMap = SvxCaseMap::SmallCaps;
131 switch (eState)
133 case STATE_TOGGLE:
135 SvxCaseMap eTmpCaseMap = aSet.Get(RES_CHRATR_CASEMAP).GetCaseMap();
136 if (eTmpCaseMap == SvxCaseMap::SmallCaps)
137 eCaseMap = SvxCaseMap::NotMapped;
139 break;
140 case STATE_ON:
141 // Nothing to do, already set.
142 break;
143 case STATE_OFF:
144 eCaseMap = SvxCaseMap::NotMapped;
145 break;
147 SvxCaseMapItem aCaseMap(eCaseMap, RES_CHRATR_CASEMAP);
148 rSh.SetAttrItem(aCaseMap);
149 rReq.AppendItem(aCaseMap);
150 rReq.Done();
152 break;
154 case FN_UPDATE_STYLE_BY_EXAMPLE:
155 rSh.QuickUpdateStyle();
156 rReq.Done();
157 break;
159 case SID_ULINE_VAL_NONE:
161 SvxUnderlineItem aUnderline(LINESTYLE_NONE, RES_CHRATR_UNDERLINE );
162 rSh.SetAttrItem( aUnderline );
163 rReq.AppendItem( aUnderline );
164 rReq.Done();
165 break;
168 case SID_ULINE_VAL_SINGLE:
169 case SID_ULINE_VAL_DOUBLE:
170 case SID_ULINE_VAL_DOTTED:
172 FontLineStyle eOld = aSet.Get(RES_CHRATR_UNDERLINE).GetLineStyle();
173 FontLineStyle eNew = eOld;
175 switch (nWhich)
177 case SID_ULINE_VAL_SINGLE:
178 eNew = ( eOld == LINESTYLE_SINGLE ) ? LINESTYLE_NONE : LINESTYLE_SINGLE;
179 break;
180 case SID_ULINE_VAL_DOUBLE:
181 eNew = ( eOld == LINESTYLE_DOUBLE ) ? LINESTYLE_NONE : LINESTYLE_DOUBLE;
182 break;
183 case SID_ULINE_VAL_DOTTED:
184 eNew = ( eOld == LINESTYLE_DOTTED ) ? LINESTYLE_NONE : LINESTYLE_DOTTED;
185 break;
188 SvxUnderlineItem aUnderline(eNew, RES_CHRATR_UNDERLINE );
189 rSh.SetAttrItem( aUnderline );
190 rReq.AppendItem( aUnderline );
191 rReq.Done();
193 break;
194 case FN_REMOVE_DIRECT_CHAR_FORMATS:
195 if( !rSh.HasReadonlySel() && rSh.IsEndPara())
196 rSh.DontExpandFormat();
197 break;
198 default:
199 OSL_FAIL("wrong dispatcher");
200 return;
204 void SwTextShell::ExecCharAttrArgs(SfxRequest &rReq)
206 sal_uInt16 nSlot = rReq.GetSlot();
207 const SfxItemSet* pArgs = rReq.GetArgs();
208 bool bArgs = pArgs != nullptr && pArgs->Count() > 0;
209 SwWrtShell& rWrtSh = GetShell();
210 SwTextFormatColl* pColl = nullptr;
212 // Is only set if the whole paragraph is selected and AutoUpdateFormat is set.
213 if (rWrtSh.HasSelection() && rWrtSh.IsSelFullPara())
215 pColl = rWrtSh.GetCurTextFormatColl();
216 if ( pColl && !pColl->IsAutoUpdateOnDirectFormat() )
217 pColl = nullptr;
219 SfxItemPool& rPool = GetPool();
220 sal_uInt16 nWhich = rPool.GetWhich( nSlot );
221 switch (nSlot)
223 case FN_TXTATR_INET:
224 // Special treatment of the PoolId of the SwFormatInetFormat
225 if(bArgs)
227 const SfxPoolItem& rItem = pArgs->Get( nWhich );
229 SwFormatINetFormat aINetFormat( static_cast<const SwFormatINetFormat&>(rItem) );
230 if ( USHRT_MAX == aINetFormat.GetVisitedFormatId() )
232 OSL_ENSURE( false, "<SwTextShell::ExecCharAttrArgs(..)> - unexpected visited character format ID at hyperlink attribute" );
233 aINetFormat.SetVisitedFormatAndId(
234 aINetFormat.GetVisitedFormat(),
235 SwStyleNameMapper::GetPoolIdFromUIName( aINetFormat.GetVisitedFormat(), SwGetPoolIdFromName::ChrFmt ) );
237 if ( USHRT_MAX == aINetFormat.GetINetFormatId() )
239 OSL_ENSURE( false, "<SwTextShell::ExecCharAttrArgs(..)> - unexpected unvisited character format ID at hyperlink attribute" );
240 aINetFormat.SetINetFormatAndId(
241 aINetFormat.GetINetFormat(),
242 SwStyleNameMapper::GetPoolIdFromUIName( aINetFormat.GetINetFormat(), SwGetPoolIdFromName::ChrFmt ) );
245 if ( pColl )
246 pColl->SetFormatAttr( aINetFormat );
247 else
248 rWrtSh.SetAttrItem( aINetFormat );
249 rReq.Done();
251 break;
253 case FN_GROW_FONT_SIZE:
254 case FN_SHRINK_FONT_SIZE:
256 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONTHEIGHT, rPool );
257 rWrtSh.GetCurAttr( aSetItem.GetItemSet() );
258 SfxItemSet aAttrSet( rPool, aSetItem.GetItemSet().GetRanges() );
260 SvtScriptType nScriptTypes = rWrtSh.GetScriptType();
261 const SvxFontHeightItem* pSize( static_cast<const SvxFontHeightItem*>(
262 aSetItem.GetItemOfScript( nScriptTypes ) ) );
263 std::vector<std::pair< const SfxPoolItem*, std::unique_ptr<SwPaM> >> vItems;
264 // simple case where selected text has one size and
265 // (tdf#124919) selection is not multiple table cells
266 if (pSize && !rWrtSh.IsTableMode())
268 // must create new one, otherwise document is without pam
269 SwPaM* pPaM = rWrtSh.GetCursor();
270 vItems.emplace_back( pSize, std::make_unique<SwPaM>( *(pPaM->GetMark()), *(pPaM->GetPoint())) );
272 else
273 vItems = rWrtSh.GetItemWithPaM( RES_CHRATR_FONTSIZE );
275 rWrtSh.StartUndo( SwUndoId::INSATTR );
276 for( std::pair< const SfxPoolItem*, std::unique_ptr<SwPaM> >& iPair : vItems )
278 std::unique_ptr<SwPaM> pPaM = std::move(iPair.second);
279 const SfxPoolItem* pItem = iPair.first;
280 aSetItem.GetItemSet().ClearItem();
281 rWrtSh.GetPaMAttr( pPaM.get(), aSetItem.GetItemSet() );
282 aAttrSet.SetRanges( aSetItem.GetItemSet().GetRanges() );
284 pSize = static_cast<const SvxFontHeightItem*>( pItem );
285 if (pSize)
287 SvxFontHeightItem aSize(*pSize);
289 sal_uInt32 nSize = aSize.GetHeight();
291 if ( nSlot == FN_GROW_FONT_SIZE && ( nSize += nFontInc ) > nFontMaxSz )
292 nSize = nFontMaxSz;
293 else if ( nSlot == FN_SHRINK_FONT_SIZE && ( nSize -= nFontInc ) < nFontInc )
294 nSize = nFontInc;
296 aSize.SetHeight( nSize );
297 aSetItem.PutItemForScriptType( nScriptTypes, aSize );
298 aAttrSet.Put( aSetItem.GetItemSet() );
299 if( pColl )
300 pColl->SetFormatAttr( aAttrSet );
301 else
302 rWrtSh.SetAttrSet( aAttrSet, SetAttrMode::DEFAULT, pPaM.get() );
305 rWrtSh.EndUndo( SwUndoId::INSATTR );
306 rReq.Done();
308 break;
310 default:
311 OSL_FAIL("wrong dispatcher");
312 return;
316 void SwTextShell::ExecParaAttr(SfxRequest &rReq)
318 SvxAdjust eAdjst;
319 sal_uInt16 ePropL;
320 const SfxItemSet* pArgs = rReq.GetArgs();
322 // Get both attributes immediately isn't more expensive!!
323 SfxItemSetFixed
324 <RES_PARATR_LINESPACING, RES_PARATR_ADJUST,
325 RES_FRAMEDIR, RES_FRAMEDIR> aSet( GetPool() );
327 sal_uInt16 nSlot = rReq.GetSlot();
328 switch (nSlot)
330 case SID_ATTR_PARA_ADJUST:
332 if( pArgs && SfxItemState::SET == pArgs->GetItemState(RES_PARATR_ADJUST) )
334 const SvxAdjustItem& rAdj = pArgs->Get(RES_PARATR_ADJUST);
335 SvxAdjustItem aAdj( rAdj.GetAdjust(), RES_PARATR_ADJUST );
336 if ( rAdj.GetAdjust() == SvxAdjust::Block )
338 aAdj.SetLastBlock( rAdj.GetLastBlock() );
339 aAdj.SetOneWord( rAdj.GetOneWord() );
342 aSet.Put(aAdj);
345 break;
346 case SID_ATTR_PARA_ADJUST_LEFT: eAdjst = SvxAdjust::Left; goto SET_ADJUST;
347 case SID_ATTR_PARA_ADJUST_RIGHT: eAdjst = SvxAdjust::Right; goto SET_ADJUST;
348 case SID_ATTR_PARA_ADJUST_CENTER: eAdjst = SvxAdjust::Center; goto SET_ADJUST;
349 case SID_ATTR_PARA_ADJUST_BLOCK: eAdjst = SvxAdjust::Block; goto SET_ADJUST;
350 SET_ADJUST:
352 aSet.Put(SvxAdjustItem(eAdjst,RES_PARATR_ADJUST));
353 rReq.AppendItem( SfxBoolItem( GetPool().GetWhich(nSlot), true ) );
355 break;
357 case SID_ATTR_PARA_LINESPACE:
358 if(pArgs && SfxItemState::SET == pArgs->GetItemState( GetPool().GetWhich(nSlot) ))
360 SvxLineSpacingItem aLineSpace = static_cast<const SvxLineSpacingItem&>( pArgs->Get(
361 GetPool().GetWhich(nSlot)));
362 aSet.Put( aLineSpace );
364 break;
365 case SID_ATTR_PARA_LINESPACE_10: ePropL = 100; goto SET_LINESPACE;
366 case SID_ATTR_PARA_LINESPACE_15: ePropL = 150; goto SET_LINESPACE;
367 case SID_ATTR_PARA_LINESPACE_115: ePropL = 115; goto SET_LINESPACE;
368 case SID_ATTR_PARA_LINESPACE_20: ePropL = 200; goto SET_LINESPACE;
370 SET_LINESPACE:
373 SvxLineSpacingItem aLineSpacing(ePropL, RES_PARATR_LINESPACING );
374 aLineSpacing.SetLineSpaceRule( SvxLineSpaceRule::Auto );
375 if( 100 == ePropL )
376 aLineSpacing.SetInterLineSpaceRule( SvxInterLineSpaceRule::Off );
377 else
378 aLineSpacing.SetPropLineSpace(ePropL);
379 aSet.Put( aLineSpacing );
381 break;
383 case SID_ATTR_PARA_LEFT_TO_RIGHT :
384 case SID_ATTR_PARA_RIGHT_TO_LEFT :
386 SfxItemSetFixed<RES_PARATR_ADJUST, RES_PARATR_ADJUST> aAdjustSet( GetPool() );
387 GetShell().GetCurAttr(aAdjustSet);
388 bool bChgAdjust = false;
389 SfxItemState eAdjustState = aAdjustSet.GetItemState(RES_PARATR_ADJUST, false);
390 if(eAdjustState >= SfxItemState::DEFAULT)
392 SvxAdjust eAdjust =
393 aAdjustSet.Get(RES_PARATR_ADJUST).GetAdjust();
394 bChgAdjust = (SvxAdjust::Left == eAdjust && SID_ATTR_PARA_RIGHT_TO_LEFT == nSlot) ||
395 (SvxAdjust::Right == eAdjust && SID_ATTR_PARA_LEFT_TO_RIGHT == nSlot);
397 else
398 bChgAdjust = true;
400 SvxFrameDirection eFrameDirection =
401 (SID_ATTR_PARA_LEFT_TO_RIGHT == nSlot) ?
402 SvxFrameDirection::Horizontal_LR_TB : SvxFrameDirection::Horizontal_RL_TB;
403 aSet.Put( SvxFrameDirectionItem( eFrameDirection, RES_FRAMEDIR ) );
405 if (bChgAdjust)
407 SvxAdjust eAdjust = (SID_ATTR_PARA_LEFT_TO_RIGHT == nSlot) ?
408 SvxAdjust::Left : SvxAdjust::Right;
409 SvxAdjustItem aAdjust( eAdjust, RES_PARATR_ADJUST );
410 aSet.Put( aAdjust );
411 aAdjust.SetWhich(SID_ATTR_PARA_ADJUST);
412 GetView().GetViewFrame().GetBindings().SetState( aAdjust );
413 // Toggle numbering alignment
414 const SwNumRule* pCurRule = GetShell().GetNumRuleAtCurrCursorPos();
415 if( pCurRule )
417 SvxNumRule aRule = pCurRule->MakeSvxNumRule();
419 for(sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++)
421 SvxNumberFormat aFormat(aRule.GetLevel(i));
422 if(SvxAdjust::Left == aFormat.GetNumAdjust())
423 aFormat.SetNumAdjust( SvxAdjust::Right );
425 else if(SvxAdjust::Right == aFormat.GetNumAdjust())
426 aFormat.SetNumAdjust( SvxAdjust::Left );
428 aRule.SetLevel(i, aFormat, aRule.Get(i) != nullptr);
430 SwNumRule aSetRule( pCurRule->GetName(),
431 pCurRule->Get( 0 ).GetPositionAndSpaceMode() );
432 aSetRule.SetSvxRule( aRule, GetShell().GetDoc());
433 aSetRule.SetAutoRule( true );
434 // no start or continuation of a list - list style is only changed
435 GetShell().SetCurNumRule( aSetRule, false );
439 break;
441 default:
442 OSL_FAIL("wrong dispatcher");
443 return;
445 SwWrtShell& rWrtSh = GetShell();
446 SwTextFormatColl* pColl = rWrtSh.GetCurTextFormatColl();
447 if(pColl && pColl->IsAutoUpdateOnDirectFormat())
449 rWrtSh.AutoUpdatePara(pColl, aSet);
451 else
452 rWrtSh.SetAttrSet( aSet, SetAttrMode::DEFAULT, nullptr, true);
453 rReq.Done();
456 void SwTextShell::ExecParaAttrArgs(SfxRequest &rReq)
458 SwWrtShell &rSh = GetShell();
459 const SfxItemSet *pArgs = rReq.GetArgs();
460 const SfxPoolItem *pItem = nullptr;
462 sal_uInt16 nSlot = rReq.GetSlot();
463 if(pArgs)
464 pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem);
465 switch ( nSlot )
467 case FN_DROP_CHAR_STYLE_NAME:
468 if( pItem )
470 OUString sCharStyleName = static_cast<const SfxStringItem*>(pItem)->GetValue();
471 SfxItemSetFixed<RES_PARATR_DROP, RES_PARATR_DROP> aSet(GetPool());
472 rSh.GetCurAttr(aSet);
473 SwFormatDrop aDropItem(aSet.Get(RES_PARATR_DROP));
474 SwCharFormat* pFormat = nullptr;
475 if(!sCharStyleName.isEmpty())
476 pFormat = rSh.FindCharFormatByName( sCharStyleName );
477 aDropItem.SetCharFormat( pFormat );
478 aSet.Put(aDropItem);
479 rSh.SetAttrSet(aSet);
481 break;
482 case FN_FORMAT_DROPCAPS:
484 if(pItem)
486 rSh.SetAttrItem(*pItem);
487 rReq.Done();
489 else
491 SfxItemSetFixed<RES_PARATR_DROP, RES_PARATR_DROP,
492 HINT_END, HINT_END> aSet(GetPool());
493 rSh.GetCurAttr(aSet);
494 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
495 ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateSwDropCapsDialog(GetView().GetFrameWeld(), aSet));
496 if (pDlg->Execute() == RET_OK)
498 rSh.StartAction();
499 rSh.StartUndo( SwUndoId::START );
500 if ( const SfxStringItem* pHintItem = aSet.GetItemIfSet(HINT_END,false) )
502 if ( !pHintItem->GetValue().isEmpty() )
503 rSh.ReplaceDropText(pHintItem->GetValue());
505 rSh.SetAttrSet(*pDlg->GetOutputItemSet());
506 rSh.EndUndo( SwUndoId::END );
507 rSh.EndAction();
508 rReq.Done(*pDlg->GetOutputItemSet());
512 break;
513 case SID_ATTR_PARA_PAGEBREAK:
514 if(pItem)
516 rSh.SetAttrItem( *pItem );
517 rReq.Done();
519 break;
520 case SID_ATTR_PARA_MODEL:
522 if(pItem)
524 SfxItemSetFixed<RES_PAGEDESC, RES_PAGEDESC,
525 SID_ATTR_PARA_MODEL, SID_ATTR_PARA_MODEL> aCoreSet( GetPool() );
526 aCoreSet.Put(*pItem);
527 SfxToSwPageDescAttr( rSh, aCoreSet);
528 rSh.SetAttrSet(aCoreSet);
529 rReq.Done();
532 break;
534 default:
535 OSL_FAIL("wrong dispatcher");
536 return;
540 void SwTextShell::GetAttrState(SfxItemSet &rSet)
542 SwWrtShell &rSh = GetShell();
543 SfxItemPool& rPool = GetPool();
544 SfxItemSet aCoreSet(rPool, aTextFormatCollSetRange);
545 // Request *all* text attributes from the core.
546 // fdo#78737: this is called from SvxRuler, which requires the list indents!
547 rSh.GetCurAttr(aCoreSet, /* bMergeIndentValuesOfNumRule = */ true);
549 SfxWhichIter aIter(rSet);
550 sal_uInt16 nSlot = aIter.FirstWhich();
551 bool bFlag = false;
552 SfxBoolItem aFlagItem;
553 const SfxPoolItem* pItem = nullptr;
554 SvxAdjust eAdjust = SvxAdjust::Left;
555 bool bAdjustGood = false;
556 SfxItemState eState = aCoreSet.GetItemState(RES_PARATR_ADJUST, false, &pItem);
558 if( SfxItemState::DEFAULT == eState )
559 pItem = &rPool.GetDefaultItem(RES_PARATR_ADJUST);
560 if( SfxItemState::DEFAULT <= eState )
562 eAdjust = static_cast<const SvxAdjustItem* >( pItem)->GetAdjust();
563 bAdjustGood = true;
566 short nEsc = 0;
567 eState = aCoreSet.GetItemState(RES_CHRATR_ESCAPEMENT, false, &pItem);
568 if( SfxItemState::DEFAULT == eState )
569 pItem = &rPool.GetDefaultItem(RES_CHRATR_ESCAPEMENT);
570 if( eState >= SfxItemState::DEFAULT )
571 nEsc = static_cast<const SvxEscapementItem* >(pItem)->GetEsc();
573 sal_uInt16 nLineSpace = 0;
574 eState = aCoreSet.GetItemState(RES_PARATR_LINESPACING, false, &pItem);
575 if( SfxItemState::DEFAULT == eState )
576 pItem = &rPool.GetDefaultItem(RES_PARATR_LINESPACING);
577 if( SfxItemState::DEFAULT <= eState &&
578 static_cast<const SvxLineSpacingItem* >(pItem)->GetLineSpaceRule() == SvxLineSpaceRule::Auto )
580 if(SvxInterLineSpaceRule::Off ==
581 static_cast<const SvxLineSpacingItem* >(pItem)->GetInterLineSpaceRule())
582 nLineSpace = 100;
583 else
584 nLineSpace = static_cast<const SvxLineSpacingItem* >(pItem)->GetPropLineSpace();
587 SvxCaseMap eCaseMap = SvxCaseMap::NotMapped;
588 eState = aCoreSet.GetItemState(RES_CHRATR_CASEMAP, false, &pItem);
589 if (eState == SfxItemState::DEFAULT)
590 pItem = &rPool.GetDefaultItem(RES_CHRATR_CASEMAP);
591 if (eState >= SfxItemState::DEFAULT)
592 eCaseMap = static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap();
594 while (nSlot)
596 switch(nSlot)
598 case FN_SET_SUPER_SCRIPT:
599 bFlag = 0 < nEsc;
600 break;
601 case FN_SET_SUB_SCRIPT:
602 bFlag = 0 > nEsc;
603 break;
604 case FN_SET_SMALL_CAPS:
605 bFlag = eCaseMap == SvxCaseMap::SmallCaps;
606 break;
607 case SID_ATTR_PARA_ADJUST_LEFT:
608 if (!bAdjustGood)
610 rSet.InvalidateItem( nSlot );
611 nSlot = 0;
613 else
614 bFlag = SvxAdjust::Left == eAdjust;
615 break;
616 case SID_ATTR_PARA_ADJUST_RIGHT:
617 if (!bAdjustGood)
619 rSet.InvalidateItem( nSlot );
620 nSlot = 0;
622 else
623 bFlag = SvxAdjust::Right == eAdjust;
624 break;
625 case SID_ATTR_PARA_ADJUST_CENTER:
626 if (!bAdjustGood)
628 rSet.InvalidateItem( nSlot );
629 nSlot = 0;
631 else
632 bFlag = SvxAdjust::Center == eAdjust;
633 break;
634 case SID_ATTR_PARA_ADJUST_BLOCK:
636 if (!bAdjustGood)
638 rSet.InvalidateItem( nSlot );
639 nSlot = 0;
641 else
643 bFlag = SvxAdjust::Block == eAdjust;
644 sal_uInt16 nHtmlMode = GetHtmlMode(rSh.GetView().GetDocShell());
645 if((nHtmlMode & HTMLMODE_ON) && !(nHtmlMode & HTMLMODE_FULL_STYLES ))
647 rSet.DisableItem( nSlot );
648 nSlot = 0;
652 break;
653 case SID_ATTR_PARA_LINESPACE_10:
654 bFlag = nLineSpace == 100;
655 break;
656 case SID_ATTR_PARA_LINESPACE_115:
657 bFlag = nLineSpace == 115;
658 break;
659 case SID_ATTR_PARA_LINESPACE_15:
660 bFlag = nLineSpace == 150;
661 break;
662 case SID_ATTR_PARA_LINESPACE_20:
663 bFlag = nLineSpace == 200;
664 break;
665 case FN_GROW_FONT_SIZE:
666 case FN_SHRINK_FONT_SIZE:
668 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONTHEIGHT,
669 *rSet.GetPool() );
670 aSetItem.GetItemSet().Put( aCoreSet, false );
671 const SvxFontHeightItem* pSize( static_cast<const SvxFontHeightItem*>(
672 aSetItem.GetItemOfScript( rSh.GetScriptType() ) ) );
674 if( pSize ) // selection is of one size
676 sal_uInt32 nSize = pSize->GetHeight();
677 if( nSize == nFontMaxSz )
678 rSet.DisableItem( FN_GROW_FONT_SIZE );
679 else if( nSize == nFontInc )
680 rSet.DisableItem( FN_SHRINK_FONT_SIZE );
682 else
684 std::vector<std::pair< const SfxPoolItem*, std::unique_ptr<SwPaM> >>
685 vFontHeight = rSh.GetItemWithPaM( RES_CHRATR_FONTSIZE );
686 for ( const std::pair< const SfxPoolItem*, std::unique_ptr<SwPaM>>& aIt : vFontHeight )
688 if (!aIt.first)
690 rSet.DisableItem(FN_GROW_FONT_SIZE);
691 rSet.DisableItem(FN_SHRINK_FONT_SIZE);
692 break;
694 pSize = static_cast<const SvxFontHeightItem*>( aIt.first );
695 sal_uInt32 nSize = pSize->GetHeight();
696 if( nSize == nFontMaxSz )
697 rSet.DisableItem( FN_GROW_FONT_SIZE );
698 else if( nSize == nFontInc )
699 rSet.DisableItem( FN_SHRINK_FONT_SIZE );
702 nSlot = 0;
704 break;
705 case SID_ULINE_VAL_NONE:
706 case SID_ULINE_VAL_SINGLE:
707 case SID_ULINE_VAL_DOUBLE:
708 case SID_ULINE_VAL_DOTTED:
710 eState = aCoreSet.GetItemState(RES_CHRATR_UNDERLINE);
711 if( eState >= SfxItemState::DEFAULT )
713 FontLineStyle eLineStyle = aCoreSet.Get(RES_CHRATR_UNDERLINE).GetLineStyle();
715 switch (nSlot)
717 case SID_ULINE_VAL_NONE:
718 rSet.Put(SfxBoolItem(nSlot, eLineStyle == LINESTYLE_NONE));
719 break;
720 case SID_ULINE_VAL_SINGLE:
721 rSet.Put(SfxBoolItem(nSlot, eLineStyle == LINESTYLE_SINGLE));
722 break;
723 case SID_ULINE_VAL_DOUBLE:
724 rSet.Put(SfxBoolItem(nSlot, eLineStyle == LINESTYLE_DOUBLE));
725 break;
726 case SID_ULINE_VAL_DOTTED:
727 rSet.Put(SfxBoolItem(nSlot, eLineStyle == LINESTYLE_DOTTED));
728 break;
731 else
732 rSet.InvalidateItem(nSlot);
733 nSlot = 0;
735 break;
736 case SID_ATTR_PARA_ADJUST:
737 if (!bAdjustGood)
738 rSet.InvalidateItem( nSlot );
739 else
740 rSet.Put(SvxAdjustItem(eAdjust, SID_ATTR_PARA_ADJUST ));
741 nSlot = 0;
742 break;
743 case SID_ATTR_PARA_LRSPACE:
744 case SID_ATTR_PARA_LEFTSPACE:
745 case SID_ATTR_PARA_RIGHTSPACE:
746 case SID_ATTR_PARA_FIRSTLINESPACE:
748 eState = aCoreSet.GetItemState(RES_MARGIN_FIRSTLINE);
749 eState = std::min(aCoreSet.GetItemState(RES_MARGIN_TEXTLEFT), eState);
750 eState = std::min(aCoreSet.GetItemState(RES_MARGIN_RIGHT), eState);
751 if( eState >= SfxItemState::DEFAULT )
753 SvxLRSpaceItem aLR(RES_LR_SPACE);
754 SvxFirstLineIndentItem const& rFirstLine(aCoreSet.Get(RES_MARGIN_FIRSTLINE));
755 SvxTextLeftMarginItem const& rLeftMargin(aCoreSet.Get(RES_MARGIN_TEXTLEFT));
756 SvxRightMarginItem const& rRightMargin(aCoreSet.Get(RES_MARGIN_RIGHT));
757 aLR.SetTextFirstLineOffset(rFirstLine.GetTextFirstLineOffset(), rFirstLine.GetPropTextFirstLineOffset());
758 aLR.SetAutoFirst(rFirstLine.IsAutoFirst());
759 aLR.SetTextLeft(rLeftMargin.GetTextLeft(), rLeftMargin.GetPropLeft());
760 aLR.SetRight(rRightMargin.GetRight(), rRightMargin.GetPropRight());
761 aLR.SetWhich(nSlot);
762 rSet.Put(aLR);
764 else
765 rSet.InvalidateItem(nSlot);
766 nSlot = 0;
768 break;
770 case SID_ATTR_PARA_LEFT_TO_RIGHT :
771 case SID_ATTR_PARA_RIGHT_TO_LEFT :
773 if ( !SvtCTLOptions::IsCTLFontEnabled() )
775 rSet.DisableItem( nSlot );
776 nSlot = 0;
778 else
780 // is the item set?
781 sal_uInt16 nHtmlMode = GetHtmlMode(rSh.GetView().GetDocShell());
782 if((!(nHtmlMode & HTMLMODE_ON) || (0 != (nHtmlMode & HTMLMODE_SOME_STYLES))) &&
783 aCoreSet.GetItemState( RES_FRAMEDIR, false ) >= SfxItemState::DEFAULT)
785 SvxFrameDirection eFrameDir =
786 aCoreSet.Get(RES_FRAMEDIR).GetValue();
787 if (SvxFrameDirection::Environment == eFrameDir)
789 eFrameDir = rSh.IsInRightToLeftText() ?
790 SvxFrameDirection::Horizontal_RL_TB : SvxFrameDirection::Horizontal_LR_TB;
792 bFlag = (SID_ATTR_PARA_LEFT_TO_RIGHT == nSlot &&
793 SvxFrameDirection::Horizontal_LR_TB == eFrameDir) ||
794 (SID_ATTR_PARA_RIGHT_TO_LEFT == nSlot &&
795 SvxFrameDirection::Horizontal_RL_TB == eFrameDir);
797 else
799 rSet.InvalidateItem(nSlot);
800 nSlot = 0;
804 break;
806 case SID_ATTR_CHAR_LANGUAGE:
807 case SID_ATTR_CHAR_KERNING:
808 case RES_PARATR_DROP:
810 rSet.Put(aCoreSet.Get( GetPool().GetWhich(nSlot)));
811 nSlot = 0;
813 break;
814 case SID_ATTR_PARA_MODEL:
816 SfxItemSetFixed
817 <RES_PAGEDESC,RES_PAGEDESC,
818 SID_ATTR_PARA_MODEL,SID_ATTR_PARA_MODEL> aTemp(GetPool());
819 aTemp.Put(aCoreSet);
820 ::SwToSfxPageDescAttr(aTemp);
821 rSet.Put(aTemp.Get(SID_ATTR_PARA_MODEL));
822 nSlot = 0;
824 break;
825 case RES_TXTATR_INETFMT:
827 SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
828 rSh.GetCurAttr(aSet);
829 const SfxPoolItem& rItem = aSet.Get(RES_TXTATR_INETFMT);
830 rSet.Put(rItem);
831 nSlot = 0;
833 break;
835 default:
836 // Do nothing
837 nSlot = 0;
838 break;
841 if( nSlot )
843 aFlagItem.SetWhich( nSlot );
844 aFlagItem.SetValue( bFlag );
845 rSet.Put( aFlagItem );
847 nSlot = aIter.NextWhich();
850 rSet.Put(aCoreSet,false);
853 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */