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 <sfx2/sfxdlg.hxx>
27 #include <editeng/numitem.hxx>
28 #include <strings.hxx>
30 #include <svx/svxids.hrc>
31 #include <OutlineView.hxx>
32 #include <DrawDocShell.hxx>
33 #include <DrawViewShell.hxx>
35 #include <drawdoc.hxx>
36 #include <sdabstdlg.hxx>
37 #include <svx/nbdtmg.hxx>
38 #include <svx/nbdtmgfact.hxx>
39 #include <svx/svdoutl.hxx>
43 using namespace svx::sidebar
;
46 FuBulletAndPosition::FuBulletAndPosition(ViewShell
* pViewShell
, ::sd::Window
* pWindow
,
47 ::sd::View
* pView
, SdDrawDocument
* pDoc
,
49 : FuPoor(pViewShell
, pWindow
, pView
, pDoc
, rReq
)
53 rtl::Reference
<FuPoor
> FuBulletAndPosition::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
55 rtl::Reference
<FuPoor
> xFunc( new FuBulletAndPosition( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
56 xFunc
->DoExecute(rReq
);
60 void FuBulletAndPosition::DoExecute( SfxRequest
& rReq
)
62 const sal_uInt16 nSId
= rReq
.GetSlot();
63 if ( nSId
== FN_SVX_SET_BULLET
|| nSId
== FN_SVX_SET_NUMBER
)
65 SetCurrentBulletsNumbering(rReq
);
69 const SfxItemSet
* pArgs
= rReq
.GetArgs();
70 const SfxStringItem
* pPageItem
= SfxItemSet::GetItem
<SfxStringItem
>(pArgs
, FN_PARAM_1
, false);
72 if ( pArgs
&& !pPageItem
)
74 /* not direct to pOlView; therefore, SdDrawView::SetAttributes can catch
75 changes to master page and redirect to a template */
76 mpView
->SetAttributes(*pArgs
);
80 // fill ItemSet for Dialog
81 SfxItemSet
aEditAttr( mpDoc
->GetPool() );
82 mpView
->GetAttributes( aEditAttr
);
84 SfxItemSet
aNewAttr( mpViewShell
->GetPool(),
85 svl::Items
<EE_ITEMS_START
, EE_ITEMS_END
>{} );
86 aNewAttr
.Put( aEditAttr
, false );
90 // create and execute dialog
91 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
92 ScopedVclPtr
<AbstractSvxBulletAndPositionDlg
> pDlg(pFact
->CreateSvxBulletAndPositionDlg(mpViewShell
->GetFrameWeld(), &aNewAttr
, mpView
));
93 sal_uInt16 nResult
= pDlg
->Execute();
95 if( nResult
== RET_OK
)
97 const SfxItemSet
pOutputSet( *pDlg
->GetOutputItemSet( &aNewAttr
) );
98 pView
->SetAttributes(pOutputSet
, /*bReplaceAll=*/false, /*bSlide*/ pDlg
->IsSlideScope(), /*bMaster=*/pDlg
->IsApplyToMaster());
104 void FuBulletAndPosition::SetCurrentBulletsNumbering(SfxRequest
& rReq
)
106 if (!mpDoc
|| !mpView
)
109 const sal_uInt16 nSId
= rReq
.GetSlot();
110 if ( nSId
!= FN_SVX_SET_BULLET
&& nSId
!= FN_SVX_SET_NUMBER
)
112 // unexpected SfxRequest
116 const SfxUInt16Item
* pItem
= rReq
.GetArg
<SfxUInt16Item
>(nSId
);
123 SfxItemSet
aNewAttr( mpViewShell
->GetPool(), svl::Items
<EE_ITEMS_START
, EE_ITEMS_END
>{} );
125 SfxItemSet
aEditAttr( mpDoc
->GetPool() );
126 mpView
->GetAttributes( aEditAttr
);
127 aNewAttr
.Put( aEditAttr
, false );
130 const DrawViewShell
* pDrawViewShell
= dynamic_cast< DrawViewShell
* >(mpViewShell
);
131 //Init bullet level in "Customize" tab page in bullet dialog in master page view
132 const bool bInMasterView
= pDrawViewShell
&& pDrawViewShell
->GetEditMode() == EditMode::MasterPage
;
135 SdrObject
* pObj
= mpView
->GetTextEditObject();
136 if( pObj
&& pObj
->GetObjIdentifier() == OBJ_OUTLINETEXT
)
138 const sal_uInt16 nLevel
= mpView
->GetSelectionLevel();
139 if( nLevel
!= 0xFFFF )
141 //save the itemset value
142 SfxItemSet
aStoreSet( aNewAttr
);
143 aNewAttr
.ClearItem();
145 aNewAttr
.MergeRange( SID_PARAM_NUM_PRESET
, SID_PARAM_CUR_NUM_LEVEL
);
146 aNewAttr
.Put( aStoreSet
);
147 //put current level user selected
148 aNewAttr
.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL
, nLevel
) );
153 sal_uInt16 nIdx
= pItem
->GetValue();
154 bool bToggle
= false;
155 if( nIdx
== sal_uInt16(0xFFFF) )
157 // If the nIdx is (sal_uInt16)0xFFFF, means set bullet status to on/off
163 sal_uInt32 nNumItemId
= SID_ATTR_NUMBERING_RULE
;
164 const SfxPoolItem
* pTmpItem
= GetNumBulletItem( aNewAttr
, nNumItemId
);
165 std::unique_ptr
<SvxNumRule
> pNumRule
;
168 pNumRule
.reset(new SvxNumRule(*static_cast<const SvxNumBulletItem
*>(pTmpItem
)->GetNumRule()));
170 // get numbering rule corresponding to <nIdx> and apply the needed number formats to <pNumRule>
171 NBOTypeMgrBase
* pNumRuleMgr
=
172 NBOutlineTypeMgrFact::CreateInstance(
173 nSId
== FN_SVX_SET_BULLET
? NBOType::Bullets
: NBOType::Numbering
);
176 sal_uInt16 nActNumLvl
= sal_uInt16(0xFFFF);
177 const SfxPoolItem
* pNumLevelItem
= nullptr;
178 if(SfxItemState::SET
== aNewAttr
.GetItemState(SID_PARAM_CUR_NUM_LEVEL
, false, &pNumLevelItem
))
179 nActNumLvl
= static_cast<const SfxUInt16Item
*>(pNumLevelItem
)->GetValue();
181 pNumRuleMgr
->SetItems(&aNewAttr
);
182 SvxNumRule
aTmpRule( *pNumRule
);
183 if ( nSId
== FN_SVX_SET_BULLET
&& bToggle
&& nIdx
==0 )
185 // for toggling bullets get default numbering rule
186 pNumRuleMgr
->ApplyNumRule( aTmpRule
, nIdx
, nActNumLvl
, true );
190 pNumRuleMgr
->ApplyNumRule( aTmpRule
, nIdx
, nActNumLvl
);
193 sal_uInt16 nMask
= 1;
194 for(sal_uInt16 i
= 0; i
< pNumRule
->GetLevelCount(); i
++)
196 if(nActNumLvl
& nMask
)
198 const SvxNumberFormat
& aFmt(aTmpRule
.GetLevel(i
));
199 pNumRule
->SetLevel(i
, aFmt
);
206 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
207 std::unique_ptr
<OutlineViewModelChangeGuard
, o3tl::default_delete
<OutlineViewModelChangeGuard
>> aGuard
;
208 if (OutlineView
* pView
= dynamic_cast<OutlineView
*>(mpView
))
210 pOLV
= pView
->GetViewByWindow(mpViewShell
->GetActiveWindow());
211 aGuard
.reset(new OutlineViewModelChangeGuard(*pView
));
214 SdrOutliner
* pOwner
= bInMasterView
? mpView
->GetTextEditOutliner() : nullptr;
215 const bool bOutlinerUndoEnabled
= pOwner
&& !pOwner
->IsInUndo() && pOwner
->IsUndoEnabled();
216 SdrModel
* pSdrModel
= bInMasterView
? mpView
->GetModel() : nullptr;
217 const bool bModelUndoEnabled
= pSdrModel
&& pSdrModel
->IsUndoEnabled();
219 if ( bOutlinerUndoEnabled
)
221 pOwner
->UndoActionStart( OLUNDO_ATTR
);
223 else if ( bModelUndoEnabled
)
225 pSdrModel
->BegUndo();
230 pOLV
->ToggleBulletsNumbering( bToggle
, nSId
== FN_SVX_SET_BULLET
, bInMasterView
? nullptr : pNumRule
.get() );
234 mpView
->ChangeMarkedObjectsBulletsNumbering( bToggle
, nSId
== FN_SVX_SET_BULLET
, bInMasterView
? nullptr : pNumRule
.get() );
237 if (bInMasterView
&& pNumRule
)
239 SfxItemSet
aSetAttr( mpViewShell
->GetPool(), svl::Items
<EE_ITEMS_START
, EE_ITEMS_END
>{} );
240 aSetAttr
.Put(SvxNumBulletItem( *pNumRule
, nNumItemId
));
241 mpView
->SetAttributes(aSetAttr
);
244 if( bOutlinerUndoEnabled
)
246 pOwner
->UndoActionEnd();
248 else if ( bModelUndoEnabled
)
250 pSdrModel
->EndUndo();
257 const SfxPoolItem
* FuBulletAndPosition::GetNumBulletItem(SfxItemSet
& aNewAttr
, sal_uInt32
& nNumItemId
)
259 //SvxNumBulletItem* pRetItem = NULL;
260 const SfxPoolItem
* pTmpItem
= nullptr;
262 if(aNewAttr
.GetItemState(nNumItemId
, false, &pTmpItem
) == SfxItemState::SET
)
268 nNumItemId
= aNewAttr
.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE
);
269 SfxItemState eState
= aNewAttr
.GetItemState(nNumItemId
, false, &pTmpItem
);
270 if (eState
== SfxItemState::SET
)
274 bool bOutliner
= false;
279 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
280 const size_t nCount
= rMarkList
.GetMarkCount();
282 for(size_t nNum
= 0; nNum
< nCount
; ++nNum
)
284 SdrObject
* pObj
= rMarkList
.GetMark(nNum
)->GetMarkedSdrObj();
285 if( pObj
->GetObjInventor() == SdrInventor::Default
)
287 switch(pObj
->GetObjIdentifier())
292 case OBJ_OUTLINETEXT
:
300 const SvxNumBulletItem
*pItem
= nullptr;
303 SfxStyleSheetBasePool
* pSSPool
= mpView
->GetDocSh()->GetStyleSheetPool();
304 SfxStyleSheetBase
* pFirstStyleSheet
= pSSPool
->Find( STR_LAYOUT_OUTLINE
" 1", SfxStyleFamily::Pseudo
);
305 if( pFirstStyleSheet
)
306 pFirstStyleSheet
->GetItemSet().GetItemState(EE_PARA_NUMBULLET
, false, reinterpret_cast<const SfxPoolItem
**>(&pItem
));
309 if( pItem
== nullptr )
310 pItem
= aNewAttr
.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET
);
312 //DBG_ASSERT( pItem, "No EE_PARA_NUMBULLET in the Pool!" );
314 std::unique_ptr
<SfxPoolItem
> pNewItem(pItem
->CloneSetWhich(EE_PARA_NUMBULLET
));
315 aNewAttr
.Put(*pNewItem
);
317 if(bTitle
&& aNewAttr
.GetItemState(EE_PARA_NUMBULLET
) == SfxItemState::SET
)
319 const SvxNumBulletItem
* pBulletItem
= aNewAttr
.GetItem(EE_PARA_NUMBULLET
);
320 SvxNumRule
* pLclRule
= pBulletItem
->GetNumRule();
323 SvxNumRule
aNewRule( *pLclRule
);
324 aNewRule
.SetFeatureFlag( SvxNumRuleFlags::NO_NUMBERS
);
326 SvxNumBulletItem
aNewItem( aNewRule
, EE_PARA_NUMBULLET
);
327 aNewAttr
.Put(aNewItem
);
331 SfxItemState eItemState
= aNewAttr
.GetItemState(nNumItemId
, false, &pTmpItem
);
332 if (eItemState
== SfxItemState::SET
)
336 //DBG_ASSERT(eState == SfxItemState::SET, "No item found");
342 } // end of namespace sd
344 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */