Line data Source code
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 <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"
29 :
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 {
44 :
45 0 : TYPEINIT1( FuOutlineBullet, FuPoor );
46 :
47 0 : FuOutlineBullet::FuOutlineBullet(ViewShell* pViewShell, ::sd::Window* pWindow,
48 : ::sd::View* pView, SdDrawDocument* pDoc,
49 : SfxRequest& rReq)
50 0 : : FuPoor(pViewShell, pWindow, pView, pDoc, rReq)
51 : {
52 0 : }
53 :
54 0 : rtl::Reference<FuPoor> FuOutlineBullet::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
55 : {
56 0 : rtl::Reference<FuPoor> xFunc( new FuOutlineBullet( pViewSh, pWin, pView, pDoc, rReq ) );
57 0 : xFunc->DoExecute(rReq);
58 0 : return xFunc;
59 : }
60 :
61 0 : void FuOutlineBullet::DoExecute( SfxRequest& rReq )
62 : {
63 0 : const sal_uInt16 nSId = rReq.GetSlot();
64 0 : if ( nSId == FN_SVX_SET_BULLET || nSId == FN_SVX_SET_NUMBER )
65 : {
66 0 : SetCurrentBulletsNumbering(rReq);
67 0 : return;
68 : }
69 :
70 0 : const SfxItemSet* pArgs = rReq.GetArgs();
71 0 : SFX_ITEMSET_ARG( pArgs, pPageItem, SfxStringItem, FN_PARAM_1, false );
72 :
73 0 : if ( !pArgs || pPageItem )
74 : {
75 : // fill ItemSet for Dialog
76 0 : SfxItemSet aEditAttr( mpDoc->GetPool() );
77 0 : mpView->GetAttributes( aEditAttr );
78 :
79 0 : SfxItemSet aNewAttr( mpViewShell->GetPool(),
80 0 : EE_ITEMS_START, EE_ITEMS_END );
81 0 : aNewAttr.Put( aEditAttr, false );
82 :
83 : // create and execute dialog
84 0 : SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
85 0 : boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact ? pFact->CreateSdOutlineBulletTabDlg( NULL, &aNewAttr, mpView ) : 0);
86 0 : if( pDlg )
87 : {
88 0 : if ( pPageItem )
89 0 : pDlg->SetCurPageId( OUStringToOString( pPageItem->GetValue(), RTL_TEXTENCODING_UTF8 ) );
90 0 : sal_uInt16 nResult = pDlg->Execute();
91 :
92 0 : switch( nResult )
93 : {
94 : case RET_OK:
95 : {
96 0 : SfxItemSet aSet( *pDlg->GetOutputItemSet() );
97 :
98 0 : OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
99 :
100 0 : boost::scoped_ptr< OutlineViewModelChangeGuard > aGuard;
101 :
102 0 : if (mpView->ISA(OutlineView))
103 : {
104 : pOLV = static_cast<OutlineView*>(mpView)
105 0 : ->GetViewByWindow(mpViewShell->GetActiveWindow());
106 :
107 0 : aGuard.reset( new OutlineViewModelChangeGuard( static_cast<OutlineView&>(*mpView) ) );
108 : }
109 :
110 0 : if( pOLV )
111 0 : pOLV->EnableBullets();
112 :
113 0 : rReq.Done( aSet );
114 0 : pArgs = rReq.GetArgs();
115 : }
116 0 : break;
117 :
118 : default:
119 0 : return;
120 : }
121 0 : }
122 : }
123 :
124 : /* not direct to pOlView; therefore, SdDrawView::SetAttributes can catch
125 : changes to master page and redirect to a template */
126 0 : mpView->SetAttributes(*pArgs);
127 :
128 : /* #i35937#
129 : // invalidate possible affected fields
130 : mpViewShell->Invalidate( FN_NUM_BULLET_ON );
131 : */
132 : }
133 :
134 0 : void FuOutlineBullet::SetCurrentBulletsNumbering(SfxRequest& rReq)
135 : {
136 0 : if (!mpDoc || !mpView)
137 0 : return;
138 :
139 0 : const sal_uInt16 nSId = rReq.GetSlot();
140 0 : if ( nSId != FN_SVX_SET_BULLET && nSId != FN_SVX_SET_NUMBER )
141 : {
142 : // unexpected SfxRequest
143 0 : return;
144 : }
145 :
146 0 : SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, nSId, false );
147 0 : if ( !pItem )
148 : {
149 0 : rReq.Done();
150 0 : return;
151 : }
152 :
153 0 : SfxItemSet aNewAttr( mpViewShell->GetPool(), EE_ITEMS_START, EE_ITEMS_END );
154 : {
155 0 : SfxItemSet aEditAttr( mpDoc->GetPool() );
156 0 : mpView->GetAttributes( aEditAttr );
157 0 : aNewAttr.Put( aEditAttr, false );
158 : }
159 :
160 0 : const DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >(mpViewShell);
161 : //Init bullet level in "Customize" tab page in bullet dialog in master page view
162 0 : const bool bInMasterView = pDrawViewShell && pDrawViewShell->GetEditMode() == EM_MASTERPAGE;
163 0 : if ( bInMasterView )
164 : {
165 0 : SdrObject* pObj = mpView->GetTextEditObject();
166 0 : if( pObj && pObj->GetObjIdentifier() == OBJ_OUTLINETEXT )
167 : {
168 0 : const sal_uInt16 nLevel = mpView->GetSelectionLevel();
169 0 : if( nLevel != 0xFFFF )
170 : {
171 : //save the itemset value
172 0 : SfxItemSet aStoreSet( aNewAttr );
173 0 : aNewAttr.ClearItem();
174 : //extend range
175 0 : aNewAttr.MergeRange( SID_PARAM_NUM_PRESET, SID_PARAM_CUR_NUM_LEVEL );
176 0 : aNewAttr.Put( aStoreSet );
177 : //put current level user selected
178 0 : aNewAttr.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
179 : }
180 : }
181 : }
182 :
183 0 : sal_uInt16 nIdx = pItem->GetValue();
184 0 : bool bToggle = false;
185 0 : if( nIdx == (sal_uInt16)0xFFFF )
186 : {
187 : // If the nIdx is (sal_uInt16)0xFFFF, means set bullet status to on/off
188 0 : nIdx = 1;
189 0 : bToggle = true;
190 : }
191 0 : nIdx--;
192 :
193 0 : sal_uInt32 nNumItemId = SID_ATTR_NUMBERING_RULE;
194 0 : const SfxPoolItem* pTmpItem = GetNumBulletItem( aNewAttr, nNumItemId );
195 0 : SvxNumRule* pNumRule = NULL;
196 0 : if ( pTmpItem )
197 : {
198 0 : pNumRule = new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pTmpItem)->GetNumRule());
199 :
200 : // get numbering rule corresponding to <nIdx> and apply the needed number formats to <pNumRule>
201 : NBOTypeMgrBase* pNumRuleMgr =
202 : NBOutlineTypeMgrFact::CreateInstance(
203 0 : nSId == FN_SVX_SET_BULLET ? eNBOType::BULLETS : eNBOType::NUMBERING );
204 0 : if ( pNumRuleMgr )
205 : {
206 0 : sal_uInt16 nActNumLvl = (sal_uInt16)0xFFFF;
207 0 : const SfxPoolItem* pNumLevelItem = NULL;
208 0 : if(SfxItemState::SET == aNewAttr.GetItemState(SID_PARAM_CUR_NUM_LEVEL, false, &pNumLevelItem))
209 0 : nActNumLvl = static_cast<const SfxUInt16Item*>(pNumLevelItem)->GetValue();
210 :
211 0 : pNumRuleMgr->SetItems(&aNewAttr);
212 0 : SvxNumRule aTmpRule( *pNumRule );
213 0 : if ( nSId == FN_SVX_SET_BULLET && bToggle && nIdx==0 )
214 : {
215 : // for toggling bullets get default numbering rule
216 0 : pNumRuleMgr->ApplyNumRule( aTmpRule, nIdx, nActNumLvl, true );
217 : }
218 : else
219 : {
220 0 : pNumRuleMgr->ApplyNumRule( aTmpRule, nIdx, nActNumLvl );
221 : }
222 :
223 0 : sal_uInt16 nMask = 1;
224 0 : for(sal_uInt16 i = 0; i < pNumRule->GetLevelCount(); i++)
225 : {
226 0 : if(nActNumLvl & nMask)
227 : {
228 0 : SvxNumberFormat aFmt(aTmpRule.GetLevel(i));
229 0 : pNumRule->SetLevel(i, aFmt);
230 : }
231 0 : nMask <<= 1;
232 0 : }
233 : }
234 : }
235 :
236 0 : OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
237 0 : boost::scoped_ptr< OutlineViewModelChangeGuard > aGuard;
238 : {
239 0 : if (mpView->ISA(OutlineView))
240 : {
241 : pOLV = static_cast<OutlineView*>(mpView)
242 0 : ->GetViewByWindow(mpViewShell->GetActiveWindow());
243 :
244 0 : aGuard.reset( new OutlineViewModelChangeGuard( static_cast<OutlineView&>(*mpView) ) );
245 : }
246 : }
247 :
248 0 : SdrOutliner* pOwner = bInMasterView ? mpView->GetTextEditOutliner() : 0;
249 0 : const bool bOutlinerUndoEnabled = pOwner && !pOwner->IsInUndo() && pOwner->IsUndoEnabled();
250 0 : SdrModel* pSdrModel = bInMasterView ? mpView->GetModel() : 0;
251 0 : const bool bModelUndoEnabled = pSdrModel && pSdrModel->IsUndoEnabled();
252 :
253 0 : if ( bOutlinerUndoEnabled )
254 : {
255 0 : pOwner->UndoActionStart( OLUNDO_ATTR );
256 : }
257 0 : else if ( bModelUndoEnabled )
258 : {
259 0 : pSdrModel->BegUndo();
260 : }
261 :
262 0 : if ( pOLV )
263 : {
264 0 : pOLV->ToggleBulletsNumbering( bToggle, nSId == FN_SVX_SET_BULLET, bInMasterView ? 0 : pNumRule );
265 : }
266 : else
267 : {
268 0 : mpView->ChangeMarkedObjectsBulletsNumbering( bToggle, nSId == FN_SVX_SET_BULLET, bInMasterView ? 0 : pNumRule );
269 : }
270 0 : if ( bInMasterView )
271 : {
272 0 : SfxItemSet aSetAttr( mpViewShell->GetPool(), EE_ITEMS_START, EE_ITEMS_END );
273 0 : aSetAttr.Put(SvxNumBulletItem( *pNumRule ), nNumItemId);
274 0 : mpView->SetAttributes(aSetAttr);
275 : }
276 :
277 0 : if( bOutlinerUndoEnabled )
278 : {
279 0 : pOwner->UndoActionEnd( OLUNDO_ATTR );
280 : }
281 0 : else if ( bModelUndoEnabled )
282 : {
283 0 : pSdrModel->EndUndo();
284 : }
285 :
286 0 : delete pNumRule;
287 0 : rReq.Done();
288 : }
289 :
290 0 : const SfxPoolItem* FuOutlineBullet::GetNumBulletItem(SfxItemSet& aNewAttr, sal_uInt32& nNumItemId)
291 : {
292 : //SvxNumBulletItem* pRetItem = NULL;
293 0 : const SfxPoolItem* pTmpItem = NULL;
294 :
295 0 : if(aNewAttr.GetItemState(nNumItemId, false, &pTmpItem) == SfxItemState::SET)
296 : {
297 0 : return pTmpItem;
298 : }
299 : else
300 : {
301 0 : nNumItemId = aNewAttr.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
302 0 : SfxItemState eState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
303 0 : if (eState == SfxItemState::SET)
304 0 : return pTmpItem;
305 : else
306 : {
307 0 : bool bOutliner = false;
308 0 : bool bTitle = false;
309 :
310 0 : if( mpView )
311 : {
312 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
313 0 : const size_t nCount = rMarkList.GetMarkCount();
314 :
315 0 : for(size_t nNum = 0; nNum < nCount; ++nNum)
316 : {
317 0 : SdrObject* pObj = rMarkList.GetMark(nNum)->GetMarkedSdrObj();
318 0 : if( pObj->GetObjInventor() == SdrInventor )
319 : {
320 0 : switch(pObj->GetObjIdentifier())
321 : {
322 : case OBJ_TITLETEXT:
323 0 : bTitle = true;
324 0 : break;
325 : case OBJ_OUTLINETEXT:
326 0 : bOutliner = true;
327 0 : break;
328 : }
329 : }
330 : }
331 : }
332 :
333 0 : const SvxNumBulletItem *pItem = NULL;
334 0 : if(bOutliner)
335 : {
336 0 : SfxStyleSheetBasePool* pSSPool = mpView->GetDocSh()->GetStyleSheetPool();
337 0 : OUString aStyleName(SD_RESSTR(STR_LAYOUT_OUTLINE) + " 1");
338 0 : SfxStyleSheetBase* pFirstStyleSheet = pSSPool->Find( aStyleName, SD_STYLE_FAMILY_PSEUDO);
339 0 : if( pFirstStyleSheet )
340 0 : pFirstStyleSheet->GetItemSet().GetItemState(EE_PARA_NUMBULLET, false, reinterpret_cast<const SfxPoolItem**>(&pItem));
341 : }
342 :
343 0 : if( pItem == NULL )
344 0 : pItem = static_cast<const SvxNumBulletItem*>( aNewAttr.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET) );
345 :
346 : //DBG_ASSERT( pItem, "No EE_PARA_NUMBULLET in the Pool!" );
347 :
348 0 : aNewAttr.Put(*pItem, EE_PARA_NUMBULLET);
349 :
350 0 : if(bTitle && aNewAttr.GetItemState(EE_PARA_NUMBULLET,true) == SfxItemState::SET )
351 : {
352 0 : const SvxNumBulletItem* pBulletItem = static_cast<const SvxNumBulletItem*>( aNewAttr.GetItem(EE_PARA_NUMBULLET,true) );
353 0 : SvxNumRule* pLclRule = pBulletItem->GetNumRule();
354 0 : if(pLclRule)
355 : {
356 0 : SvxNumRule aNewRule( *pLclRule );
357 0 : aNewRule.SetFeatureFlag( SvxNumRuleFlags::NO_NUMBERS, true );
358 :
359 0 : SvxNumBulletItem aNewItem( aNewRule, EE_PARA_NUMBULLET );
360 0 : aNewAttr.Put(aNewItem);
361 : }
362 : }
363 :
364 0 : SfxItemState eItemState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
365 0 : if (eItemState == SfxItemState::SET)
366 0 : return pTmpItem;
367 :
368 : }
369 : //DBG_ASSERT(eState == SfxItemState::SET, "No item found");
370 : }
371 0 : return pTmpItem;
372 : }
373 :
374 66 : } // end of namespace sd
375 :
376 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|