LibreOffice Module sd (master) 1
fuolbull.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
28
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>
40
41using namespace svx::sidebar;
42namespace sd {
43
45 ::sd::View* pView, SdDrawDocument* pDoc,
46 SfxRequest& rReq)
47 : FuPoor(pViewShell, pWindow, pView, pDoc, rReq)
48{
49}
50
52{
53 rtl::Reference<FuPoor> xFunc( new FuBulletAndPosition( pViewSh, pWin, pView, pDoc, rReq ) );
54 xFunc->DoExecute(rReq);
55 return xFunc;
56}
57
59{
60 const sal_uInt16 nSId = rReq.GetSlot();
61 if ( nSId == FN_SVX_SET_BULLET || nSId == FN_SVX_SET_NUMBER )
62 {
64 return;
65 }
66
67 const SfxItemSet* pArgs = rReq.GetArgs();
68 const SfxStringItem* pPageItem = SfxItemSet::GetItem<SfxStringItem>(pArgs, FN_PARAM_1, false);
69
70 if ( pArgs && !pPageItem )
71 {
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;
76 }
77
78 // fill ItemSet for Dialog
79 SfxItemSet aEditAttr( mpDoc->GetPool() );
80 mpView->GetAttributes( aEditAttr );
81
83 aNewAttr.Put( aEditAttr, false );
84
85 auto pView = mpView;
86
87 // create and execute dialog
90 sal_uInt16 nResult = pDlg->Execute();
91
92 if( nResult == RET_OK )
93 {
94 OutlinerView* pOLV = pView->GetTextEditOutlinerView();
95
96 std::unique_ptr<OutlineViewModelChangeGuard, o3tl::default_delete<OutlineViewModelChangeGuard>> aGuard;
97
98 if (OutlineView* pOutlineView = dynamic_cast<OutlineView*>(pView))
99 {
100 pOLV = pOutlineView->GetViewByWindow(mpViewShell->GetActiveWindow());
101 aGuard.reset(new OutlineViewModelChangeGuard(*pOutlineView));
102 }
103
104 if( pOLV )
105 pOLV->EnsureNumberingIsOn();
106
107 const SfxItemSet pOutputSet( *pDlg->GetOutputItemSet( &aNewAttr ) );
108 pView->SetAttributes(pOutputSet, /*bReplaceAll=*/false, /*bSlide*/ pDlg->IsSlideScope(), /*bMaster=*/pDlg->IsApplyToMaster());
109 }
110
111 rReq.Done();
112}
113
115{
116 if (!mpDoc || !mpView)
117 return;
118
119 const sal_uInt16 nSId = rReq.GetSlot();
120 if ( nSId != FN_SVX_SET_BULLET && nSId != FN_SVX_SET_NUMBER )
121 {
122 // unexpected SfxRequest
123 return;
124 }
125
126 const SfxUInt16Item* pItem = rReq.GetArg<SfxUInt16Item>(nSId);
127 if ( !pItem )
128 {
129 rReq.Done();
130 return;
131 }
132
134 {
135 SfxItemSet aEditAttr( mpDoc->GetPool() );
136 mpView->GetAttributes( aEditAttr );
137 aNewAttr.Put( aEditAttr, false );
138 }
139
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;
143 if ( bInMasterView )
144 {
146 if( pObj && pObj->GetObjIdentifier() == SdrObjKind::OutlineText )
147 {
148 const sal_uInt16 nLevel = mpView->GetSelectionLevel();
149 if( nLevel != 0xFFFF )
150 {
151 //save the itemset value
152 SfxItemSet aStoreSet( aNewAttr );
153 aNewAttr.ClearItem();
154 //extend range
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 ) );
159 }
160 }
161 }
162
163 sal_uInt16 nIdx = pItem->GetValue();
164 bool bToggle = false;
165 if( nIdx == sal_uInt16(0xFFFF) )
166 {
167 // If the nIdx is (sal_uInt16)0xFFFF, means set bullet status to on/off
168 nIdx = 1;
169 bToggle = true;
170 }
171 nIdx--;
172
173 TypedWhichId<SvxNumBulletItem> nNumItemId = SID_ATTR_NUMBERING_RULE;
174 const SfxPoolItem* pTmpItem = GetNumBulletItem( aNewAttr, nNumItemId );
175 std::unique_ptr<SvxNumRule> pNumRule;
176 if ( pTmpItem )
177 {
178 pNumRule.reset(new SvxNumRule(static_cast<const SvxNumBulletItem*>(pTmpItem)->GetNumRule()));
179
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 );
184 if ( pNumRuleMgr )
185 {
186 sal_uInt16 nActNumLvl = sal_uInt16(0xFFFF);
187 if(const SfxUInt16Item* pNumLevelItem = aNewAttr.GetItemIfSet(SID_PARAM_CUR_NUM_LEVEL, false))
188 nActNumLvl = pNumLevelItem->GetValue();
189
190 pNumRuleMgr->SetItems(&aNewAttr);
191 SvxNumRule aTmpRule( *pNumRule );
192 if ( nSId == FN_SVX_SET_BULLET && bToggle && nIdx==0 )
193 {
194 // for toggling bullets get default numbering rule
195 pNumRuleMgr->ApplyNumRule( aTmpRule, nIdx, nActNumLvl, true );
196 }
197 else
198 {
199 pNumRuleMgr->ApplyNumRule( aTmpRule, nIdx, nActNumLvl );
200 }
201
202 sal_uInt16 nMask = 1;
203 for(sal_uInt16 i = 0; i < pNumRule->GetLevelCount(); i++)
204 {
205 if(nActNumLvl & nMask)
206 {
207 const SvxNumberFormat& aFmt(aTmpRule.GetLevel(i));
208 pNumRule->SetLevel(i, aFmt);
209 }
210 nMask <<= 1;
211 }
212 }
213 }
214
216 std::unique_ptr<OutlineViewModelChangeGuard, o3tl::default_delete<OutlineViewModelChangeGuard>> aGuard;
217 if (OutlineView* pView = dynamic_cast<OutlineView*>(mpView))
218 {
219 pOLV = pView->GetViewByWindow(mpViewShell->GetActiveWindow());
220 aGuard.reset(new OutlineViewModelChangeGuard(*pView));
221 }
222
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();
227
228 if ( bOutlinerUndoEnabled )
229 {
230 pOwner->UndoActionStart( OLUNDO_ATTR );
231 }
232 else if ( bModelUndoEnabled )
233 {
234 pSdrModel->BegUndo();
235 }
236
237 if ( pOLV )
238 {
239 pOLV->ToggleBulletsNumbering( bToggle, nSId == FN_SVX_SET_BULLET, bInMasterView ? nullptr : pNumRule.get() );
240 }
241 else
242 {
243 mpView->ChangeMarkedObjectsBulletsNumbering( bToggle, nSId == FN_SVX_SET_BULLET, bInMasterView ? nullptr : pNumRule.get() );
244 }
245
246 if (bInMasterView && pNumRule)
247 {
249 aSetAttr.Put(SvxNumBulletItem( *pNumRule, nNumItemId ));
250 mpView->SetAttributes(aSetAttr);
251 }
252
253 if( bOutlinerUndoEnabled )
254 {
255 pOwner->UndoActionEnd();
256 }
257 else if ( bModelUndoEnabled )
258 {
259 pSdrModel->EndUndo();
260 }
261
262 pNumRule.reset();
263 rReq.Done();
264}
265
267{
268 const SvxNumBulletItem* pTmpItem = aNewAttr.GetItemIfSet(nNumItemId, false);
269
270 if(pTmpItem)
271 return pTmpItem;
272
273 nNumItemId = aNewAttr.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
274 pTmpItem = aNewAttr.GetItemIfSet(nNumItemId, false);
275 if (pTmpItem)
276 return pTmpItem;
277
278 bool bOutliner = false;
279 bool bTitle = false;
280
281 if( mpView )
282 {
283 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
284 const size_t nCount = rMarkList.GetMarkCount();
285
286 for(size_t nNum = 0; nNum < nCount; ++nNum)
287 {
288 SdrObject* pObj = rMarkList.GetMark(nNum)->GetMarkedSdrObj();
289 if( pObj->GetObjInventor() == SdrInventor::Default )
290 {
291 switch(pObj->GetObjIdentifier())
292 {
293 case SdrObjKind::TitleText:
294 bTitle = true;
295 break;
296 case SdrObjKind::OutlineText:
297 bOutliner = true;
298 break;
299 default:
300 break;
301 }
302 }
303 }
304 }
305
306 const SvxNumBulletItem *pItem = nullptr;
307 if(bOutliner)
308 {
310 SfxStyleSheetBase* pFirstStyleSheet = pSSPool->Find( STR_LAYOUT_OUTLINE + " 1", SfxStyleFamily::Pseudo);
311 if( pFirstStyleSheet )
312 pItem = pFirstStyleSheet->GetItemSet().GetItemIfSet(EE_PARA_NUMBULLET, false);
313 }
314
315 if( pItem == nullptr )
317
318 //DBG_ASSERT( pItem, "No EE_PARA_NUMBULLET in the Pool!" );
319
320 aNewAttr.Put(pItem->CloneSetWhich(EE_PARA_NUMBULLET));
321
322 if(bTitle && aNewAttr.GetItemState(EE_PARA_NUMBULLET) == SfxItemState::SET )
323 {
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 );
328
329 SvxNumBulletItem aNewItem( std::move(aNewRule), EE_PARA_NUMBULLET );
330 aNewAttr.Put(aNewItem);
331 }
332
333 pTmpItem = aNewAttr.GetItemIfSet(nNumItemId, false);
334 return pTmpItem;
335}
336
337
338} // end of namespace sd
339
340/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetValue() const
void ToggleBulletsNumbering(const bool bToggle, const bool bHandleBullets, const SvxNumRule *pNumRule)
void EnsureNumberingIsOn()
virtual VclPtr< AbstractSvxBulletAndPositionDlg > CreateSvxBulletAndPositionDlg(weld::Window *pParent, const SfxItemSet *pAttr, ::sd::View *pView)=0
static SD_DLLPUBLIC SdAbstractDialogFactory * Create()
Definition: sdabstdlg.cxx:38
SAL_DLLPRIVATE SfxItemPool & GetPool()
Definition: drawdoc.hxx:237
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
SdrObject * GetMarkedSdrObj() const
void BegUndo()
bool IsUndoEnabled() const
void EndUndo()
sal_uInt16 GetSelectionLevel() const
SdrTextObj * GetTextEditObject() const
const OutlinerView * GetTextEditOutlinerView() const
const SdrOutliner * GetTextEditOutliner() const
virtual SdrInventor GetObjInventor() const
virtual SdrObjKind GetObjIdentifier() const
SdrModel & GetModel() const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
SfxItemPool * GetSecondaryPool() const
const SfxPoolItem * GetPoolDefaultItem(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void MergeRange(sal_uInt16 nFrom, sal_uInt16 nTo)
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() const
const T * GetArg(sal_uInt16 nSlotId) const
void Done(bool bRemove=false)
SfxItemPool & GetPool() const
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
virtual SfxItemSet & GetItemSet()
const SvxNumRule & GetNumRule() const
const SvxNumberFormat & GetLevel(sal_uInt16 nLevel) const
void SetFeatureFlag(SvxNumRuleFlags nFlag, bool bSet=true)
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
Definition: docshel4.cxx:690
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
EditMode GetEditMode() const
void SetCurrentBulletsNumbering(SfxRequest &rReq)
Definition: fuolbull.cxx:114
virtual void DoExecute(SfxRequest &rReq) override
Definition: fuolbull.cxx:58
const SvxNumBulletItem * GetNumBulletItem(SfxItemSet &aNewAttr, TypedWhichId< SvxNumBulletItem > &nNumItemId)
Definition: fuolbull.cxx:266
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuolbull.cxx:51
FuBulletAndPosition(ViewShell *pViewShell, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuolbull.cxx:44
Base class for all functions.
Definition: fupoor.hxx:48
SdDrawDocument * mpDoc
Definition: fupoor.hxx:148
ViewShell * mpViewShell
Definition: fupoor.hxx:145
::sd::View * mpView
Definition: fupoor.hxx:144
Derivative of sd::View for the outline mode |* .
Definition: OutlineView.hxx:55
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
::sd::Window * GetActiveWindow() const
The active window is usually the mpContentWindow.
Definition: ViewShell.hxx:155
SD_DLLPUBLIC weld::Window * GetFrameWeld() const
Definition: viewshel.cxx:1582
DrawDocShell * GetDocSh() const
Definition: View.hxx:142
virtual bool SetAttributes(const SfxItemSet &rSet, bool bReplaceAll=false, bool bSlide=false, bool bMaster=false)
Definition: sdview.cxx:509
virtual void GetAttributes(SfxItemSet &rTargetSet, bool bOnlyHardAttr=false) const
Definition: sdview.cxx:515
void ChangeMarkedObjectsBulletsNumbering(const bool bToggle, const bool bHandleBullets, const SvxNumRule *pNumRule)
change the bullets/numbering of the marked objects
Definition: sdview.cxx:1286
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
void SetItems(const SfxItemSet *pArg)
virtual void ApplyNumRule(SvxNumRule &aNum, sal_uInt16 nIndex, sal_uInt16 mLevel, bool isDefault=false, bool isResetSize=false)=0
int nCount
constexpr TypedWhichId< SvxNumBulletItem > EE_PARA_NUMBULLET(EE_PARA_START+5)
SvLinkSource * pOwner
SwNumRule * GetNumRule(SwTextFormatColl &rTextFormatColl)
int i
#define OLUNDO_ATTR
constexpr OUStringLiteral STR_LAYOUT_OUTLINE
Definition: strings.hxx:16
RET_OK