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 <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>
34 #include <drawdoc.hxx>
35 #include <sdabstdlg.hxx>
36 #include <svx/nbdtmg.hxx>
37 #include <svx/nbdtmgfact.hxx>
38 #include <svx/svdoutl.hxx>
41 using namespace svx::sidebar
;
44 FuBulletAndPosition::FuBulletAndPosition(ViewShell
* pViewShell
, ::sd::Window
* pWindow
,
45 ::sd::View
* pView
, SdDrawDocument
* pDoc
,
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
);
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
);
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
);
78 // fill ItemSet for Dialog
79 SfxItemSet
aEditAttr( mpDoc
->GetPool() );
80 mpView
->GetAttributes( aEditAttr
);
82 SfxItemSetFixed
<EE_PARA_NUMBULLET
, EE_PARA_BULLET
> aNewAttr( mpViewShell
->GetPool() );
83 aNewAttr
.Put( aEditAttr
, false );
87 // create and execute dialog
88 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
89 ScopedVclPtr
<AbstractSvxBulletAndPositionDlg
> pDlg(pFact
->CreateSvxBulletAndPositionDlg(mpViewShell
->GetFrameWeld(), &aNewAttr
, mpView
));
90 sal_uInt16 nResult
= pDlg
->Execute();
92 if( nResult
== RET_OK
)
94 OutlinerView
* pOLV
= pView
->GetTextEditOutlinerView();
96 std::unique_ptr
<OutlineViewModelChangeGuard
, o3tl::default_delete
<OutlineViewModelChangeGuard
>> aGuard
;
98 if (OutlineView
* pOutlineView
= dynamic_cast<OutlineView
*>(pView
))
100 pOLV
= pOutlineView
->GetViewByWindow(mpViewShell
->GetActiveWindow());
101 aGuard
.reset(new OutlineViewModelChangeGuard(*pOutlineView
));
105 pOLV
->EnsureNumberingIsOn();
107 const SfxItemSet
pOutputSet( *pDlg
->GetOutputItemSet( &aNewAttr
) );
108 pView
->SetAttributes(pOutputSet
, /*bReplaceAll=*/false, /*bSlide*/ pDlg
->IsSlideScope(), /*bMaster=*/pDlg
->IsApplyToMaster());
114 void FuBulletAndPosition::SetCurrentBulletsNumbering(SfxRequest
& rReq
)
116 if (!mpDoc
|| !mpView
)
119 const sal_uInt16 nSId
= rReq
.GetSlot();
120 if ( nSId
!= FN_SVX_SET_BULLET
&& nSId
!= FN_SVX_SET_NUMBER
)
122 // unexpected SfxRequest
126 const SfxUInt16Item
* pItem
= rReq
.GetArg
<SfxUInt16Item
>(nSId
);
133 SfxItemSetFixed
<EE_ITEMS_START
, EE_ITEMS_END
> aNewAttr( mpViewShell
->GetPool() );
135 SfxItemSet
aEditAttr( mpDoc
->GetPool() );
136 mpView
->GetAttributes( aEditAttr
);
137 aNewAttr
.Put( aEditAttr
, false );
140 const DrawViewShell
* pDrawViewShell
= dynamic_cast< DrawViewShell
* >(mpViewShell
);
141 //Init bullet level in "Customize" tab page in bullet dialog in master page view
142 const bool bInMasterView
= pDrawViewShell
&& pDrawViewShell
->GetEditMode() == EditMode::MasterPage
;
145 SdrObject
* pObj
= mpView
->GetTextEditObject();
146 if( pObj
&& pObj
->GetObjIdentifier() == SdrObjKind::OutlineText
)
148 const sal_uInt16 nLevel
= mpView
->GetSelectionLevel();
149 if( nLevel
!= 0xFFFF )
151 //save the itemset value
152 SfxItemSet
aStoreSet( aNewAttr
);
153 aNewAttr
.ClearItem();
155 aNewAttr
.MergeRange( SID_PARAM_NUM_PRESET
, SID_PARAM_CUR_NUM_LEVEL
);
156 aNewAttr
.Put( aStoreSet
);
157 //put current level user selected
158 aNewAttr
.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL
, nLevel
) );
163 sal_uInt16 nIdx
= pItem
->GetValue();
164 bool bToggle
= false;
165 if( nIdx
== sal_uInt16(0xFFFF) )
167 // If the nIdx is (sal_uInt16)0xFFFF, means set bullet status to on/off
173 TypedWhichId
<SvxNumBulletItem
> nNumItemId
= SID_ATTR_NUMBERING_RULE
;
174 const SfxPoolItem
* pTmpItem
= GetNumBulletItem( aNewAttr
, nNumItemId
);
175 std::unique_ptr
<SvxNumRule
> pNumRule
;
178 pNumRule
.reset(new SvxNumRule(static_cast<const SvxNumBulletItem
*>(pTmpItem
)->GetNumRule()));
180 // get numbering rule corresponding to <nIdx> and apply the needed number formats to <pNumRule>
181 NBOTypeMgrBase
* pNumRuleMgr
=
182 NBOutlineTypeMgrFact::CreateInstance(
183 nSId
== FN_SVX_SET_BULLET
? NBOType::Bullets
: NBOType::Numbering
);
186 sal_uInt16 nActNumLvl
= sal_uInt16(0xFFFF);
187 if(const SfxUInt16Item
* pNumLevelItem
= aNewAttr
.GetItemIfSet(SID_PARAM_CUR_NUM_LEVEL
, false))
188 nActNumLvl
= pNumLevelItem
->GetValue();
190 pNumRuleMgr
->SetItems(&aNewAttr
);
191 SvxNumRule
aTmpRule( *pNumRule
);
192 if ( nSId
== FN_SVX_SET_BULLET
&& bToggle
&& nIdx
==0 )
194 // for toggling bullets get default numbering rule
195 pNumRuleMgr
->ApplyNumRule( aTmpRule
, nIdx
, nActNumLvl
, true );
199 pNumRuleMgr
->ApplyNumRule( aTmpRule
, nIdx
, nActNumLvl
);
202 sal_uInt16 nMask
= 1;
203 for(sal_uInt16 i
= 0; i
< pNumRule
->GetLevelCount(); i
++)
205 if(nActNumLvl
& nMask
)
207 const SvxNumberFormat
& aFmt(aTmpRule
.GetLevel(i
));
208 pNumRule
->SetLevel(i
, aFmt
);
215 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
216 std::unique_ptr
<OutlineViewModelChangeGuard
, o3tl::default_delete
<OutlineViewModelChangeGuard
>> aGuard
;
217 if (OutlineView
* pView
= dynamic_cast<OutlineView
*>(mpView
))
219 pOLV
= pView
->GetViewByWindow(mpViewShell
->GetActiveWindow());
220 aGuard
.reset(new OutlineViewModelChangeGuard(*pView
));
223 SdrOutliner
* pOwner
= bInMasterView
? mpView
->GetTextEditOutliner() : nullptr;
224 const bool bOutlinerUndoEnabled
= pOwner
&& !pOwner
->IsInUndo() && pOwner
->IsUndoEnabled();
225 SdrModel
* pSdrModel
= bInMasterView
? &mpView
->GetModel() : nullptr;
226 const bool bModelUndoEnabled
= pSdrModel
&& pSdrModel
->IsUndoEnabled();
228 if ( bOutlinerUndoEnabled
)
230 pOwner
->UndoActionStart( OLUNDO_ATTR
);
232 else if ( bModelUndoEnabled
)
234 pSdrModel
->BegUndo();
239 pOLV
->ToggleBulletsNumbering( bToggle
, nSId
== FN_SVX_SET_BULLET
, bInMasterView
? nullptr : pNumRule
.get() );
243 mpView
->ChangeMarkedObjectsBulletsNumbering( bToggle
, nSId
== FN_SVX_SET_BULLET
, bInMasterView
? nullptr : pNumRule
.get() );
246 if (bInMasterView
&& pNumRule
)
248 SfxItemSetFixed
<EE_ITEMS_START
, EE_ITEMS_END
> aSetAttr( mpViewShell
->GetPool() );
249 aSetAttr
.Put(SvxNumBulletItem( *pNumRule
, nNumItemId
));
250 mpView
->SetAttributes(aSetAttr
);
253 if( bOutlinerUndoEnabled
)
255 pOwner
->UndoActionEnd();
257 else if ( bModelUndoEnabled
)
259 pSdrModel
->EndUndo();
266 const SvxNumBulletItem
* FuBulletAndPosition::GetNumBulletItem(SfxItemSet
& aNewAttr
, TypedWhichId
<SvxNumBulletItem
>& nNumItemId
)
268 const SvxNumBulletItem
* pTmpItem
= aNewAttr
.GetItemIfSet(nNumItemId
, false);
273 nNumItemId
= aNewAttr
.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE
);
274 pTmpItem
= aNewAttr
.GetItemIfSet(nNumItemId
, false);
278 bool bOutliner
= false;
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 SdrObjKind::TitleText
:
296 case SdrObjKind::OutlineText
:
306 const SvxNumBulletItem
*pItem
= nullptr;
309 SfxStyleSheetBasePool
* pSSPool
= mpView
->GetDocSh()->GetStyleSheetPool();
310 SfxStyleSheetBase
* pFirstStyleSheet
= pSSPool
->Find( STR_LAYOUT_OUTLINE
+ " 1", SfxStyleFamily::Pseudo
);
311 if( pFirstStyleSheet
)
312 pItem
= pFirstStyleSheet
->GetItemSet().GetItemIfSet(EE_PARA_NUMBULLET
, false);
315 if( pItem
== nullptr )
316 pItem
= aNewAttr
.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET
);
318 //DBG_ASSERT( pItem, "No EE_PARA_NUMBULLET in the Pool!" );
320 aNewAttr
.Put(pItem
->CloneSetWhich(EE_PARA_NUMBULLET
));
322 if(bTitle
&& aNewAttr
.GetItemState(EE_PARA_NUMBULLET
) == SfxItemState::SET
)
324 const SvxNumBulletItem
* pBulletItem
= aNewAttr
.GetItem(EE_PARA_NUMBULLET
);
325 const SvxNumRule
& rLclRule
= pBulletItem
->GetNumRule();
326 SvxNumRule
aNewRule( rLclRule
);
327 aNewRule
.SetFeatureFlag( SvxNumRuleFlags::NO_NUMBERS
);
329 SvxNumBulletItem
aNewItem( std::move(aNewRule
), EE_PARA_NUMBULLET
);
330 aNewAttr
.Put(aNewItem
);
333 pTmpItem
= aNewAttr
.GetItemIfSet(nNumItemId
, false);
338 } // end of namespace sd
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */