bump product version to 6.4.0.3
[LibreOffice.git] / sd / source / ui / func / fuolbull.cxx
bloba5fe859d4f0a865a23f74cc2fd73d61311b82d54
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 <fuolbull.hxx>
21 #include <svl/intitem.hxx>
22 #include <svl/stritem.hxx>
23 #include <editeng/outliner.hxx>
24 #include <editeng/eeitem.hxx>
25 #include <sfx2/request.hxx>
26 #include <editeng/numitem.hxx>
27 #include <strings.hxx>
29 #include <svx/svxids.hrc>
30 #include <OutlineView.hxx>
31 #include <DrawDocShell.hxx>
32 #include <DrawViewShell.hxx>
33 #include <Window.hxx>
34 #include <drawdoc.hxx>
35 #include <sdabstdlg.hxx>
36 #include <svx/nbdtmg.hxx>
37 #include <svx/nbdtmgfact.hxx>
38 #include <svx/svdoutl.hxx>
39 #include <memory>
41 using namespace svx::sidebar;
42 namespace sd {
44 FuBulletAndPosition::FuBulletAndPosition(ViewShell* pViewShell, ::sd::Window* pWindow,
45 ::sd::View* pView, SdDrawDocument* pDoc,
46 SfxRequest& rReq)
47 : FuPoor(pViewShell, pWindow, pView, pDoc, rReq)
51 rtl::Reference<FuPoor> FuBulletAndPosition::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
53 rtl::Reference<FuPoor> xFunc( new FuBulletAndPosition( pViewSh, pWin, pView, pDoc, rReq ) );
54 xFunc->DoExecute(rReq);
55 return xFunc;
58 void FuBulletAndPosition::DoExecute( SfxRequest& rReq )
60 const sal_uInt16 nSId = rReq.GetSlot();
61 if ( nSId == FN_SVX_SET_BULLET || nSId == FN_SVX_SET_NUMBER )
63 SetCurrentBulletsNumbering(rReq);
64 return;
67 const SfxItemSet* pArgs = rReq.GetArgs();
68 const SfxStringItem* pPageItem = SfxItemSet::GetItem<SfxStringItem>(pArgs, FN_PARAM_1, false);
70 if ( pArgs && !pPageItem )
72 /* not direct to pOlView; therefore, SdDrawView::SetAttributes can catch
73 changes to master page and redirect to a template */
74 mpView->SetAttributes(*pArgs);
75 return;
78 // fill ItemSet for Dialog
79 SfxItemSet aEditAttr( mpDoc->GetPool() );
80 mpView->GetAttributes( aEditAttr );
82 static const sal_uInt16 aAttrMap[] =
84 EE_PARA_NUMBULLET,
85 EE_PARA_BULLET,
89 SfxItemSet aNewAttr( mpViewShell->GetPool(), aAttrMap );
90 aNewAttr.Put( aEditAttr, false );
92 auto pView = mpView;
94 // create and execute dialog
95 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
96 ScopedVclPtr<AbstractSvxBulletAndPositionDlg> pDlg(pFact->CreateSvxBulletAndPositionDlg(mpViewShell->GetFrameWeld(), &aNewAttr, mpView));
97 sal_uInt16 nResult = pDlg->Execute();
99 if( nResult == RET_OK )
101 const SfxItemSet pOutputSet( *pDlg->GetOutputItemSet( &aNewAttr ) );
102 pView->SetAttributes(pOutputSet, /*bReplaceAll=*/false, /*bSlide*/ pDlg->IsSlideScope(), /*bMaster=*/pDlg->IsApplyToMaster());
105 rReq.Done();
108 void FuBulletAndPosition::SetCurrentBulletsNumbering(SfxRequest& rReq)
110 if (!mpDoc || !mpView)
111 return;
113 const sal_uInt16 nSId = rReq.GetSlot();
114 if ( nSId != FN_SVX_SET_BULLET && nSId != FN_SVX_SET_NUMBER )
116 // unexpected SfxRequest
117 return;
120 const SfxUInt16Item* pItem = rReq.GetArg<SfxUInt16Item>(nSId);
121 if ( !pItem )
123 rReq.Done();
124 return;
127 SfxItemSet aNewAttr( mpViewShell->GetPool(), svl::Items<EE_ITEMS_START, EE_ITEMS_END>{} );
129 SfxItemSet aEditAttr( mpDoc->GetPool() );
130 mpView->GetAttributes( aEditAttr );
131 aNewAttr.Put( aEditAttr, false );
134 const DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >(mpViewShell);
135 //Init bullet level in "Customize" tab page in bullet dialog in master page view
136 const bool bInMasterView = pDrawViewShell && pDrawViewShell->GetEditMode() == EditMode::MasterPage;
137 if ( bInMasterView )
139 SdrObject* pObj = mpView->GetTextEditObject();
140 if( pObj && pObj->GetObjIdentifier() == OBJ_OUTLINETEXT )
142 const sal_uInt16 nLevel = mpView->GetSelectionLevel();
143 if( nLevel != 0xFFFF )
145 //save the itemset value
146 SfxItemSet aStoreSet( aNewAttr );
147 aNewAttr.ClearItem();
148 //extend range
149 aNewAttr.MergeRange( SID_PARAM_NUM_PRESET, SID_PARAM_CUR_NUM_LEVEL );
150 aNewAttr.Put( aStoreSet );
151 //put current level user selected
152 aNewAttr.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
157 sal_uInt16 nIdx = pItem->GetValue();
158 bool bToggle = false;
159 if( nIdx == sal_uInt16(0xFFFF) )
161 // If the nIdx is (sal_uInt16)0xFFFF, means set bullet status to on/off
162 nIdx = 1;
163 bToggle = true;
165 nIdx--;
167 sal_uInt32 nNumItemId = SID_ATTR_NUMBERING_RULE;
168 const SfxPoolItem* pTmpItem = GetNumBulletItem( aNewAttr, nNumItemId );
169 std::unique_ptr<SvxNumRule> pNumRule;
170 if ( pTmpItem )
172 pNumRule.reset(new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pTmpItem)->GetNumRule()));
174 // get numbering rule corresponding to <nIdx> and apply the needed number formats to <pNumRule>
175 NBOTypeMgrBase* pNumRuleMgr =
176 NBOutlineTypeMgrFact::CreateInstance(
177 nSId == FN_SVX_SET_BULLET ? NBOType::Bullets : NBOType::Numbering );
178 if ( pNumRuleMgr )
180 sal_uInt16 nActNumLvl = sal_uInt16(0xFFFF);
181 const SfxPoolItem* pNumLevelItem = nullptr;
182 if(SfxItemState::SET == aNewAttr.GetItemState(SID_PARAM_CUR_NUM_LEVEL, false, &pNumLevelItem))
183 nActNumLvl = static_cast<const SfxUInt16Item*>(pNumLevelItem)->GetValue();
185 pNumRuleMgr->SetItems(&aNewAttr);
186 SvxNumRule aTmpRule( *pNumRule );
187 if ( nSId == FN_SVX_SET_BULLET && bToggle && nIdx==0 )
189 // for toggling bullets get default numbering rule
190 pNumRuleMgr->ApplyNumRule( aTmpRule, nIdx, nActNumLvl, true );
192 else
194 pNumRuleMgr->ApplyNumRule( aTmpRule, nIdx, nActNumLvl );
197 sal_uInt16 nMask = 1;
198 for(sal_uInt16 i = 0; i < pNumRule->GetLevelCount(); i++)
200 if(nActNumLvl & nMask)
202 const SvxNumberFormat& aFmt(aTmpRule.GetLevel(i));
203 pNumRule->SetLevel(i, aFmt);
205 nMask <<= 1;
210 OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
211 std::unique_ptr<OutlineViewModelChangeGuard, o3tl::default_delete<OutlineViewModelChangeGuard>> aGuard;
212 if (OutlineView* pView = dynamic_cast<OutlineView*>(mpView))
214 pOLV = pView->GetViewByWindow(mpViewShell->GetActiveWindow());
215 aGuard.reset(new OutlineViewModelChangeGuard(*pView));
218 SdrOutliner* pOwner = bInMasterView ? mpView->GetTextEditOutliner() : nullptr;
219 const bool bOutlinerUndoEnabled = pOwner && !pOwner->IsInUndo() && pOwner->IsUndoEnabled();
220 SdrModel* pSdrModel = bInMasterView ? mpView->GetModel() : nullptr;
221 const bool bModelUndoEnabled = pSdrModel && pSdrModel->IsUndoEnabled();
223 if ( bOutlinerUndoEnabled )
225 pOwner->UndoActionStart( OLUNDO_ATTR );
227 else if ( bModelUndoEnabled )
229 pSdrModel->BegUndo();
232 if ( pOLV )
234 pOLV->ToggleBulletsNumbering( bToggle, nSId == FN_SVX_SET_BULLET, bInMasterView ? nullptr : pNumRule.get() );
236 else
238 mpView->ChangeMarkedObjectsBulletsNumbering( bToggle, nSId == FN_SVX_SET_BULLET, bInMasterView ? nullptr : pNumRule.get() );
241 if (bInMasterView && pNumRule)
243 SfxItemSet aSetAttr( mpViewShell->GetPool(), svl::Items<EE_ITEMS_START, EE_ITEMS_END>{} );
244 aSetAttr.Put(SvxNumBulletItem( *pNumRule, nNumItemId ));
245 mpView->SetAttributes(aSetAttr);
248 if( bOutlinerUndoEnabled )
250 pOwner->UndoActionEnd();
252 else if ( bModelUndoEnabled )
254 pSdrModel->EndUndo();
257 pNumRule.reset();
258 rReq.Done();
261 const SfxPoolItem* FuBulletAndPosition::GetNumBulletItem(SfxItemSet& aNewAttr, sal_uInt32& nNumItemId)
263 //SvxNumBulletItem* pRetItem = NULL;
264 const SfxPoolItem* pTmpItem = nullptr;
266 if(aNewAttr.GetItemState(nNumItemId, false, &pTmpItem) == SfxItemState::SET)
268 return pTmpItem;
270 else
272 nNumItemId = aNewAttr.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
273 SfxItemState eState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
274 if (eState == SfxItemState::SET)
275 return pTmpItem;
276 else
278 bool bOutliner = false;
279 bool bTitle = false;
281 if( mpView )
283 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
284 const size_t nCount = rMarkList.GetMarkCount();
286 for(size_t nNum = 0; nNum < nCount; ++nNum)
288 SdrObject* pObj = rMarkList.GetMark(nNum)->GetMarkedSdrObj();
289 if( pObj->GetObjInventor() == SdrInventor::Default )
291 switch(pObj->GetObjIdentifier())
293 case OBJ_TITLETEXT:
294 bTitle = true;
295 break;
296 case OBJ_OUTLINETEXT:
297 bOutliner = true;
298 break;
304 const SvxNumBulletItem *pItem = nullptr;
305 if(bOutliner)
307 SfxStyleSheetBasePool* pSSPool = mpView->GetDocSh()->GetStyleSheetPool();
308 SfxStyleSheetBase* pFirstStyleSheet = pSSPool->Find( STR_LAYOUT_OUTLINE " 1", SfxStyleFamily::Pseudo);
309 if( pFirstStyleSheet )
310 pFirstStyleSheet->GetItemSet().GetItemState(EE_PARA_NUMBULLET, false, reinterpret_cast<const SfxPoolItem**>(&pItem));
313 if( pItem == nullptr )
314 pItem = aNewAttr.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET);
316 //DBG_ASSERT( pItem, "No EE_PARA_NUMBULLET in the Pool!" );
318 std::unique_ptr<SfxPoolItem> pNewItem(pItem->CloneSetWhich(EE_PARA_NUMBULLET));
319 aNewAttr.Put(*pNewItem);
321 if(bTitle && aNewAttr.GetItemState(EE_PARA_NUMBULLET) == SfxItemState::SET )
323 const SvxNumBulletItem* pBulletItem = aNewAttr.GetItem(EE_PARA_NUMBULLET);
324 SvxNumRule* pLclRule = pBulletItem->GetNumRule();
325 if(pLclRule)
327 SvxNumRule aNewRule( *pLclRule );
328 aNewRule.SetFeatureFlag( SvxNumRuleFlags::NO_NUMBERS );
330 SvxNumBulletItem aNewItem( aNewRule, EE_PARA_NUMBULLET );
331 aNewAttr.Put(aNewItem);
335 SfxItemState eItemState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
336 if (eItemState == SfxItemState::SET)
337 return pTmpItem;
340 //DBG_ASSERT(eState == SfxItemState::SET, "No item found");
342 return pTmpItem;
346 } // end of namespace sd
348 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */