Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / fuolbull.cxx
blobf0a50dd10e835c3bddddffafb8ba40d0071185c5
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 <editeng/outliner.hxx>
23 #include <editeng/eeitem.hxx>
24 #include <sfx2/request.hxx>
25 #include <editeng/numitem.hxx>
26 #include <strings.hxx>
28 #include <editeng/editdata.hxx>
29 #include <svx/svxids.hrc>
30 #include <OutlineView.hxx>
31 #include <OutlineViewShell.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>
40 using namespace svx::sidebar;
41 namespace sd {
44 FuOutlineBullet::FuOutlineBullet(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> FuOutlineBullet::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
53 rtl::Reference<FuPoor> xFunc( new FuOutlineBullet( pViewSh, pWin, pView, pDoc, rReq ) );
54 xFunc->DoExecute(rReq);
55 return xFunc;
58 void FuOutlineBullet::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 // fill ItemSet for Dialog
73 SfxItemSet aEditAttr( mpDoc->GetPool() );
74 mpView->GetAttributes( aEditAttr );
76 SfxItemSet aNewAttr( mpViewShell->GetPool(),
77 svl::Items<EE_ITEMS_START, EE_ITEMS_END>{} );
78 aNewAttr.Put( aEditAttr, false );
80 // create and execute dialog
81 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
82 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact ? pFact->CreateSdOutlineBulletTabDlg(mpViewShell->GetActiveWindow(), &aNewAttr, mpView) : nullptr);
83 if( pDlg )
85 if ( pPageItem )
86 pDlg->SetCurPageId( OUStringToOString( pPageItem->GetValue(), RTL_TEXTENCODING_UTF8 ) );
87 sal_uInt16 nResult = pDlg->Execute();
89 switch( nResult )
91 case RET_OK:
93 SfxItemSet aSet( *pDlg->GetOutputItemSet() );
95 OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
97 std::unique_ptr<OutlineViewModelChangeGuard, o3tl::default_delete<OutlineViewModelChangeGuard>> aGuard;
99 if (OutlineView* pView = dynamic_cast<OutlineView*>(mpView))
101 pOLV = pView->GetViewByWindow(mpViewShell->GetActiveWindow());
102 aGuard.reset(new OutlineViewModelChangeGuard(*pView));
105 if( pOLV )
106 pOLV->EnableBullets();
108 rReq.Done( aSet );
109 pArgs = rReq.GetArgs();
111 break;
113 default:
114 return;
119 /* not direct to pOlView; therefore, SdDrawView::SetAttributes can catch
120 changes to master page and redirect to a template */
121 mpView->SetAttributes(*pArgs);
123 /* #i35937#
124 // invalidate possible affected fields
125 mpViewShell->Invalidate( FN_NUM_BULLET_ON );
129 void FuOutlineBullet::SetCurrentBulletsNumbering(SfxRequest& rReq)
131 if (!mpDoc || !mpView)
132 return;
134 const sal_uInt16 nSId = rReq.GetSlot();
135 if ( nSId != FN_SVX_SET_BULLET && nSId != FN_SVX_SET_NUMBER )
137 // unexpected SfxRequest
138 return;
141 const SfxUInt16Item* pItem = rReq.GetArg<SfxUInt16Item>(nSId);
142 if ( !pItem )
144 rReq.Done();
145 return;
148 SfxItemSet aNewAttr( mpViewShell->GetPool(), svl::Items<EE_ITEMS_START, EE_ITEMS_END>{} );
150 SfxItemSet aEditAttr( mpDoc->GetPool() );
151 mpView->GetAttributes( aEditAttr );
152 aNewAttr.Put( aEditAttr, false );
155 const DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >(mpViewShell);
156 //Init bullet level in "Customize" tab page in bullet dialog in master page view
157 const bool bInMasterView = pDrawViewShell && pDrawViewShell->GetEditMode() == EditMode::MasterPage;
158 if ( bInMasterView )
160 SdrObject* pObj = mpView->GetTextEditObject();
161 if( pObj && pObj->GetObjIdentifier() == OBJ_OUTLINETEXT )
163 const sal_uInt16 nLevel = mpView->GetSelectionLevel();
164 if( nLevel != 0xFFFF )
166 //save the itemset value
167 SfxItemSet aStoreSet( aNewAttr );
168 aNewAttr.ClearItem();
169 //extend range
170 aNewAttr.MergeRange( SID_PARAM_NUM_PRESET, SID_PARAM_CUR_NUM_LEVEL );
171 aNewAttr.Put( aStoreSet );
172 //put current level user selected
173 aNewAttr.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
178 sal_uInt16 nIdx = pItem->GetValue();
179 bool bToggle = false;
180 if( nIdx == sal_uInt16(0xFFFF) )
182 // If the nIdx is (sal_uInt16)0xFFFF, means set bullet status to on/off
183 nIdx = 1;
184 bToggle = true;
186 nIdx--;
188 sal_uInt32 nNumItemId = SID_ATTR_NUMBERING_RULE;
189 const SfxPoolItem* pTmpItem = GetNumBulletItem( aNewAttr, nNumItemId );
190 SvxNumRule* pNumRule = nullptr;
191 if ( pTmpItem )
193 pNumRule = new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pTmpItem)->GetNumRule());
195 // get numbering rule corresponding to <nIdx> and apply the needed number formats to <pNumRule>
196 NBOTypeMgrBase* pNumRuleMgr =
197 NBOutlineTypeMgrFact::CreateInstance(
198 nSId == FN_SVX_SET_BULLET ? NBOType::Bullets : NBOType::Numbering );
199 if ( pNumRuleMgr )
201 sal_uInt16 nActNumLvl = sal_uInt16(0xFFFF);
202 const SfxPoolItem* pNumLevelItem = nullptr;
203 if(SfxItemState::SET == aNewAttr.GetItemState(SID_PARAM_CUR_NUM_LEVEL, false, &pNumLevelItem))
204 nActNumLvl = static_cast<const SfxUInt16Item*>(pNumLevelItem)->GetValue();
206 pNumRuleMgr->SetItems(&aNewAttr);
207 SvxNumRule aTmpRule( *pNumRule );
208 if ( nSId == FN_SVX_SET_BULLET && bToggle && nIdx==0 )
210 // for toggling bullets get default numbering rule
211 pNumRuleMgr->ApplyNumRule( aTmpRule, nIdx, nActNumLvl, true );
213 else
215 pNumRuleMgr->ApplyNumRule( aTmpRule, nIdx, nActNumLvl );
218 sal_uInt16 nMask = 1;
219 for(sal_uInt16 i = 0; i < pNumRule->GetLevelCount(); i++)
221 if(nActNumLvl & nMask)
223 SvxNumberFormat aFmt(aTmpRule.GetLevel(i));
224 pNumRule->SetLevel(i, aFmt);
226 nMask <<= 1;
231 OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
232 std::unique_ptr<OutlineViewModelChangeGuard, o3tl::default_delete<OutlineViewModelChangeGuard>> aGuard;
233 if (OutlineView* pView = dynamic_cast<OutlineView*>(mpView))
235 pOLV = pView->GetViewByWindow(mpViewShell->GetActiveWindow());
236 aGuard.reset(new OutlineViewModelChangeGuard(*pView));
239 SdrOutliner* pOwner = bInMasterView ? mpView->GetTextEditOutliner() : nullptr;
240 const bool bOutlinerUndoEnabled = pOwner && !pOwner->IsInUndo() && pOwner->IsUndoEnabled();
241 SdrModel* pSdrModel = bInMasterView ? mpView->GetModel() : nullptr;
242 const bool bModelUndoEnabled = pSdrModel && pSdrModel->IsUndoEnabled();
244 if ( bOutlinerUndoEnabled )
246 pOwner->UndoActionStart( OLUNDO_ATTR );
248 else if ( bModelUndoEnabled )
250 pSdrModel->BegUndo();
253 if ( pOLV )
255 pOLV->ToggleBulletsNumbering( bToggle, nSId == FN_SVX_SET_BULLET, bInMasterView ? nullptr : pNumRule );
257 else
259 mpView->ChangeMarkedObjectsBulletsNumbering( bToggle, nSId == FN_SVX_SET_BULLET, bInMasterView ? nullptr : pNumRule );
262 if (bInMasterView && pNumRule)
264 SfxItemSet aSetAttr( mpViewShell->GetPool(), svl::Items<EE_ITEMS_START, EE_ITEMS_END>{} );
265 aSetAttr.Put(SvxNumBulletItem( *pNumRule, nNumItemId ));
266 mpView->SetAttributes(aSetAttr);
269 if( bOutlinerUndoEnabled )
271 pOwner->UndoActionEnd();
273 else if ( bModelUndoEnabled )
275 pSdrModel->EndUndo();
278 delete pNumRule;
279 rReq.Done();
282 const SfxPoolItem* FuOutlineBullet::GetNumBulletItem(SfxItemSet& aNewAttr, sal_uInt32& nNumItemId)
284 //SvxNumBulletItem* pRetItem = NULL;
285 const SfxPoolItem* pTmpItem = nullptr;
287 if(aNewAttr.GetItemState(nNumItemId, false, &pTmpItem) == SfxItemState::SET)
289 return pTmpItem;
291 else
293 nNumItemId = aNewAttr.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
294 SfxItemState eState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
295 if (eState == SfxItemState::SET)
296 return pTmpItem;
297 else
299 bool bOutliner = false;
300 bool bTitle = false;
302 if( mpView )
304 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
305 const size_t nCount = rMarkList.GetMarkCount();
307 for(size_t nNum = 0; nNum < nCount; ++nNum)
309 SdrObject* pObj = rMarkList.GetMark(nNum)->GetMarkedSdrObj();
310 if( pObj->GetObjInventor() == SdrInventor::Default )
312 switch(pObj->GetObjIdentifier())
314 case OBJ_TITLETEXT:
315 bTitle = true;
316 break;
317 case OBJ_OUTLINETEXT:
318 bOutliner = true;
319 break;
325 const SvxNumBulletItem *pItem = nullptr;
326 if(bOutliner)
328 SfxStyleSheetBasePool* pSSPool = mpView->GetDocSh()->GetStyleSheetPool();
329 SfxStyleSheetBase* pFirstStyleSheet = pSSPool->Find( STR_LAYOUT_OUTLINE " 1", SfxStyleFamily::Pseudo);
330 if( pFirstStyleSheet )
331 pFirstStyleSheet->GetItemSet().GetItemState(EE_PARA_NUMBULLET, false, reinterpret_cast<const SfxPoolItem**>(&pItem));
334 if( pItem == nullptr )
335 pItem = aNewAttr.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET);
337 //DBG_ASSERT( pItem, "No EE_PARA_NUMBULLET in the Pool!" );
339 std::unique_ptr<SfxPoolItem> pNewItem(pItem->CloneSetWhich(EE_PARA_NUMBULLET));
340 aNewAttr.Put(*pNewItem);
342 if(bTitle && aNewAttr.GetItemState(EE_PARA_NUMBULLET) == SfxItemState::SET )
344 const SvxNumBulletItem* pBulletItem = aNewAttr.GetItem(EE_PARA_NUMBULLET);
345 SvxNumRule* pLclRule = pBulletItem->GetNumRule();
346 if(pLclRule)
348 SvxNumRule aNewRule( *pLclRule );
349 aNewRule.SetFeatureFlag( SvxNumRuleFlags::NO_NUMBERS );
351 SvxNumBulletItem aNewItem( aNewRule, EE_PARA_NUMBULLET );
352 aNewAttr.Put(aNewItem);
356 SfxItemState eItemState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
357 if (eItemState == SfxItemState::SET)
358 return pTmpItem;
361 //DBG_ASSERT(eState == SfxItemState::SET, "No item found");
363 return pTmpItem;
366 } // end of namespace sd
368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */