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 <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>
34 #include <drawdoc.hxx>
35 #include <sdabstdlg.hxx>
36 #include <svx/nbdtmg.hxx>
37 #include <svx/nbdtmgfact.hxx>
38 #include <svx/svdoutl.hxx>
40 using namespace svx::sidebar
;
44 FuOutlineBullet::FuOutlineBullet(ViewShell
* pViewShell
, ::sd::Window
* pWindow
,
45 ::sd::View
* pView
, SdDrawDocument
* pDoc
,
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
);
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
);
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);
86 pDlg
->SetCurPageId( OUStringToOString( pPageItem
->GetValue(), RTL_TEXTENCODING_UTF8
) );
87 sal_uInt16 nResult
= pDlg
->Execute();
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
));
106 pOLV
->EnableBullets();
109 pArgs
= rReq
.GetArgs();
119 /* not direct to pOlView; therefore, SdDrawView::SetAttributes can catch
120 changes to master page and redirect to a template */
121 mpView
->SetAttributes(*pArgs
);
124 // invalidate possible affected fields
125 mpViewShell->Invalidate( FN_NUM_BULLET_ON );
129 void FuOutlineBullet::SetCurrentBulletsNumbering(SfxRequest
& rReq
)
131 if (!mpDoc
|| !mpView
)
134 const sal_uInt16 nSId
= rReq
.GetSlot();
135 if ( nSId
!= FN_SVX_SET_BULLET
&& nSId
!= FN_SVX_SET_NUMBER
)
137 // unexpected SfxRequest
141 const SfxUInt16Item
* pItem
= rReq
.GetArg
<SfxUInt16Item
>(nSId
);
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
;
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();
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
188 sal_uInt32 nNumItemId
= SID_ATTR_NUMBERING_RULE
;
189 const SfxPoolItem
* pTmpItem
= GetNumBulletItem( aNewAttr
, nNumItemId
);
190 SvxNumRule
* pNumRule
= nullptr;
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
);
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 );
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
);
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();
255 pOLV
->ToggleBulletsNumbering( bToggle
, nSId
== FN_SVX_SET_BULLET
, bInMasterView
? nullptr : pNumRule
);
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();
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
)
293 nNumItemId
= aNewAttr
.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE
);
294 SfxItemState eState
= aNewAttr
.GetItemState(nNumItemId
, false, &pTmpItem
);
295 if (eState
== SfxItemState::SET
)
299 bool bOutliner
= false;
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())
317 case OBJ_OUTLINETEXT
:
325 const SvxNumBulletItem
*pItem
= nullptr;
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();
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
)
361 //DBG_ASSERT(eState == SfxItemState::SET, "No item found");
366 } // end of namespace sd
368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */