bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / func / fuolbull.cxx
blobbbee427cd69e446e4648e5de27b70cd37ff4120a
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 <vcl/msgbox.hxx>
22 #include <svl/intitem.hxx>
23 #include <editeng/outliner.hxx>
24 #include <editeng/eeitem.hxx>
25 #include <sfx2/request.hxx>
26 #include <editeng/numitem.hxx>
27 #include "sdresid.hxx"
28 #include "glob.hrc"
30 #include <editeng/editdata.hxx>
31 #include <svx/svxids.hrc>
32 #include "OutlineView.hxx"
33 #include "OutlineViewShell.hxx"
34 #include "DrawViewShell.hxx"
35 #include "Window.hxx"
36 #include "drawdoc.hxx"
37 #include "sdabstdlg.hxx"
38 #include <svx/nbdtmg.hxx>
39 #include <svx/nbdtmgfact.hxx>
40 #include <svx/svdoutl.hxx>
41 #include <boost/scoped_ptr.hpp>
42 using namespace svx::sidebar;
43 namespace sd {
45 TYPEINIT1( FuOutlineBullet, FuPoor );
47 FuOutlineBullet::FuOutlineBullet(ViewShell* pViewShell, ::sd::Window* pWindow,
48 ::sd::View* pView, SdDrawDocument* pDoc,
49 SfxRequest& rReq)
50 : FuPoor(pViewShell, pWindow, pView, pDoc, rReq)
54 rtl::Reference<FuPoor> FuOutlineBullet::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
56 rtl::Reference<FuPoor> xFunc( new FuOutlineBullet( pViewSh, pWin, pView, pDoc, rReq ) );
57 xFunc->DoExecute(rReq);
58 return xFunc;
61 void FuOutlineBullet::DoExecute( SfxRequest& rReq )
63 const sal_uInt16 nSId = rReq.GetSlot();
64 if ( nSId == FN_SVX_SET_BULLET || nSId == FN_SVX_SET_NUMBER )
66 SetCurrentBulletsNumbering(rReq);
67 return;
70 const SfxItemSet* pArgs = rReq.GetArgs();
71 SFX_ITEMSET_ARG( pArgs, pPageItem, SfxStringItem, FN_PARAM_1, false );
73 if ( !pArgs || pPageItem )
75 // fill ItemSet for Dialog
76 SfxItemSet aEditAttr( mpDoc->GetPool() );
77 mpView->GetAttributes( aEditAttr );
79 SfxItemSet aNewAttr( mpViewShell->GetPool(),
80 EE_ITEMS_START, EE_ITEMS_END );
81 aNewAttr.Put( aEditAttr, false );
83 // create and execute dialog
84 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
85 boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact ? pFact->CreateSdOutlineBulletTabDlg( NULL, &aNewAttr, mpView ) : 0);
86 if( pDlg )
88 if ( pPageItem )
89 pDlg->SetCurPageId( OUStringToOString( pPageItem->GetValue(), RTL_TEXTENCODING_UTF8 ) );
90 sal_uInt16 nResult = pDlg->Execute();
92 switch( nResult )
94 case RET_OK:
96 SfxItemSet aSet( *pDlg->GetOutputItemSet() );
98 OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
100 boost::scoped_ptr< OutlineViewModelChangeGuard > aGuard;
102 if (mpView->ISA(OutlineView))
104 pOLV = static_cast<OutlineView*>(mpView)
105 ->GetViewByWindow(mpViewShell->GetActiveWindow());
107 aGuard.reset( new OutlineViewModelChangeGuard( static_cast<OutlineView&>(*mpView) ) );
110 if( pOLV )
111 pOLV->EnableBullets();
113 rReq.Done( aSet );
114 pArgs = rReq.GetArgs();
116 break;
118 default:
119 return;
124 /* not direct to pOlView; therefore, SdDrawView::SetAttributes can catch
125 changes to master page and redirect to a template */
126 mpView->SetAttributes(*pArgs);
128 /* #i35937#
129 // invalidate possible affected fields
130 mpViewShell->Invalidate( FN_NUM_BULLET_ON );
134 void FuOutlineBullet::SetCurrentBulletsNumbering(SfxRequest& rReq)
136 if (!mpDoc || !mpView)
137 return;
139 const sal_uInt16 nSId = rReq.GetSlot();
140 if ( nSId != FN_SVX_SET_BULLET && nSId != FN_SVX_SET_NUMBER )
142 // unexpected SfxRequest
143 return;
146 SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, nSId, false );
147 if ( !pItem )
149 rReq.Done();
150 return;
153 SfxItemSet aNewAttr( mpViewShell->GetPool(), EE_ITEMS_START, EE_ITEMS_END );
155 SfxItemSet aEditAttr( mpDoc->GetPool() );
156 mpView->GetAttributes( aEditAttr );
157 aNewAttr.Put( aEditAttr, false );
160 const DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >(mpViewShell);
161 //Init bullet level in "Customize" tab page in bullet dialog in master page view
162 const bool bInMasterView = pDrawViewShell && pDrawViewShell->GetEditMode() == EM_MASTERPAGE;
163 if ( bInMasterView )
165 SdrObject* pObj = mpView->GetTextEditObject();
166 if( pObj && pObj->GetObjIdentifier() == OBJ_OUTLINETEXT )
168 const sal_uInt16 nLevel = mpView->GetSelectionLevel();
169 if( nLevel != 0xFFFF )
171 //save the itemset value
172 SfxItemSet aStoreSet( aNewAttr );
173 aNewAttr.ClearItem();
174 //extend range
175 aNewAttr.MergeRange( SID_PARAM_NUM_PRESET, SID_PARAM_CUR_NUM_LEVEL );
176 aNewAttr.Put( aStoreSet );
177 //put current level user selected
178 aNewAttr.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
183 sal_uInt16 nIdx = pItem->GetValue();
184 bool bToggle = false;
185 if( nIdx == (sal_uInt16)0xFFFF )
187 // If the nIdx is (sal_uInt16)0xFFFF, means set bullet status to on/off
188 nIdx = 1;
189 bToggle = true;
191 nIdx--;
193 sal_uInt32 nNumItemId = SID_ATTR_NUMBERING_RULE;
194 const SfxPoolItem* pTmpItem = GetNumBulletItem( aNewAttr, nNumItemId );
195 SvxNumRule* pNumRule = NULL;
196 if ( pTmpItem )
198 pNumRule = new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pTmpItem)->GetNumRule());
200 // get numbering rule corresponding to <nIdx> and apply the needed number formats to <pNumRule>
201 NBOTypeMgrBase* pNumRuleMgr =
202 NBOutlineTypeMgrFact::CreateInstance(
203 nSId == FN_SVX_SET_BULLET ? eNBOType::BULLETS : eNBOType::NUMBERING );
204 if ( pNumRuleMgr )
206 sal_uInt16 nActNumLvl = (sal_uInt16)0xFFFF;
207 const SfxPoolItem* pNumLevelItem = NULL;
208 if(SfxItemState::SET == aNewAttr.GetItemState(SID_PARAM_CUR_NUM_LEVEL, false, &pNumLevelItem))
209 nActNumLvl = static_cast<const SfxUInt16Item*>(pNumLevelItem)->GetValue();
211 pNumRuleMgr->SetItems(&aNewAttr);
212 SvxNumRule aTmpRule( *pNumRule );
213 if ( nSId == FN_SVX_SET_BULLET && bToggle && nIdx==0 )
215 // for toggling bullets get default numbering rule
216 pNumRuleMgr->ApplyNumRule( aTmpRule, nIdx, nActNumLvl, true );
218 else
220 pNumRuleMgr->ApplyNumRule( aTmpRule, nIdx, nActNumLvl );
223 sal_uInt16 nMask = 1;
224 for(sal_uInt16 i = 0; i < pNumRule->GetLevelCount(); i++)
226 if(nActNumLvl & nMask)
228 SvxNumberFormat aFmt(aTmpRule.GetLevel(i));
229 pNumRule->SetLevel(i, aFmt);
231 nMask <<= 1;
236 OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
237 boost::scoped_ptr< OutlineViewModelChangeGuard > aGuard;
239 if (mpView->ISA(OutlineView))
241 pOLV = static_cast<OutlineView*>(mpView)
242 ->GetViewByWindow(mpViewShell->GetActiveWindow());
244 aGuard.reset( new OutlineViewModelChangeGuard( static_cast<OutlineView&>(*mpView) ) );
248 SdrOutliner* pOwner = bInMasterView ? mpView->GetTextEditOutliner() : 0;
249 const bool bOutlinerUndoEnabled = pOwner && !pOwner->IsInUndo() && pOwner->IsUndoEnabled();
250 SdrModel* pSdrModel = bInMasterView ? mpView->GetModel() : 0;
251 const bool bModelUndoEnabled = pSdrModel && pSdrModel->IsUndoEnabled();
253 if ( bOutlinerUndoEnabled )
255 pOwner->UndoActionStart( OLUNDO_ATTR );
257 else if ( bModelUndoEnabled )
259 pSdrModel->BegUndo();
262 if ( pOLV )
264 pOLV->ToggleBulletsNumbering( bToggle, nSId == FN_SVX_SET_BULLET, bInMasterView ? 0 : pNumRule );
266 else
268 mpView->ChangeMarkedObjectsBulletsNumbering( bToggle, nSId == FN_SVX_SET_BULLET, bInMasterView ? 0 : pNumRule, false );
270 if ( bInMasterView )
272 SfxItemSet aSetAttr( mpViewShell->GetPool(), EE_ITEMS_START, EE_ITEMS_END );
273 aSetAttr.Put(SvxNumBulletItem( *pNumRule ), nNumItemId);
274 mpView->SetAttributes(aSetAttr);
277 if( bOutlinerUndoEnabled )
279 pOwner->UndoActionEnd( OLUNDO_ATTR );
281 else if ( bModelUndoEnabled )
283 pSdrModel->EndUndo();
286 delete pNumRule;
287 rReq.Done();
290 const SfxPoolItem* FuOutlineBullet::GetNumBulletItem(SfxItemSet& aNewAttr, sal_uInt32& nNumItemId)
292 //SvxNumBulletItem* pRetItem = NULL;
293 const SfxPoolItem* pTmpItem = NULL;
295 if(aNewAttr.GetItemState(nNumItemId, false, &pTmpItem) == SfxItemState::SET)
297 return pTmpItem;
299 else
301 nNumItemId = aNewAttr.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
302 SfxItemState eState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
303 if (eState == SfxItemState::SET)
304 return pTmpItem;
305 else
307 bool bOutliner = false;
308 bool bTitle = false;
310 if( mpView )
312 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
313 const size_t nCount = rMarkList.GetMarkCount();
315 for(size_t nNum = 0; nNum < nCount; ++nNum)
317 SdrObject* pObj = rMarkList.GetMark(nNum)->GetMarkedSdrObj();
318 if( pObj->GetObjInventor() == SdrInventor )
320 switch(pObj->GetObjIdentifier())
322 case OBJ_TITLETEXT:
323 bTitle = true;
324 break;
325 case OBJ_OUTLINETEXT:
326 bOutliner = true;
327 break;
333 const SvxNumBulletItem *pItem = NULL;
334 if(bOutliner)
336 SfxStyleSheetBasePool* pSSPool = mpView->GetDocSh()->GetStyleSheetPool();
337 OUString aStyleName(SD_RESSTR(STR_LAYOUT_OUTLINE) + " 1");
338 SfxStyleSheetBase* pFirstStyleSheet = pSSPool->Find( aStyleName, SD_STYLE_FAMILY_PSEUDO);
339 if( pFirstStyleSheet )
340 pFirstStyleSheet->GetItemSet().GetItemState(EE_PARA_NUMBULLET, false, reinterpret_cast<const SfxPoolItem**>(&pItem));
343 if( pItem == NULL )
344 pItem = static_cast<const SvxNumBulletItem*>( aNewAttr.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET) );
346 //DBG_ASSERT( pItem, "No EE_PARA_NUMBULLET in the Pool!" );
348 aNewAttr.Put(*pItem, EE_PARA_NUMBULLET);
350 if(bTitle && aNewAttr.GetItemState(EE_PARA_NUMBULLET,true) == SfxItemState::SET )
352 const SvxNumBulletItem* pBulletItem = static_cast<const SvxNumBulletItem*>( aNewAttr.GetItem(EE_PARA_NUMBULLET,true) );
353 SvxNumRule* pLclRule = pBulletItem->GetNumRule();
354 if(pLclRule)
356 SvxNumRule aNewRule( *pLclRule );
357 aNewRule.SetFeatureFlag( SvxNumRuleFlags::NO_NUMBERS, true );
359 SvxNumBulletItem aNewItem( aNewRule, EE_PARA_NUMBULLET );
360 aNewAttr.Put(aNewItem);
364 SfxItemState eItemState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
365 if (eItemState == SfxItemState::SET)
366 return pTmpItem;
369 //DBG_ASSERT(eState == SfxItemState::SET, "No item found");
371 return pTmpItem;
374 } // end of namespace sd
376 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */