xref: /aoo42x/main/sd/source/ui/func/fuolbull.cxx (revision 766ce4d0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 
28 #include "fuolbull.hxx"
29 #include <vcl/msgbox.hxx>
30 #include <svl/intitem.hxx>
31 #include <editeng/outliner.hxx>
32 #include <editeng/eeitem.hxx>
33 #include <sfx2/request.hxx>
34 #include <svl/intitem.hxx>
35 #include <editeng/numitem.hxx>
36 #include "sdresid.hxx"
37 #include "glob.hrc"
38 
39 #include <editeng/editdata.hxx>
40 #include <svx/svxids.hrc>
41 #include "OutlineView.hxx"
42 #include "OutlineViewShell.hxx"
43 #include "DrawViewShell.hxx"
44 #ifndef SD_WINDOW_SHELL_HXX
45 #include "Window.hxx"
46 #endif
47 #include "drawdoc.hxx"
48 #include "sdabstdlg.hxx"
49 #include <svx/nbdtmg.hxx>
50 #include <svx/nbdtmgfact.hxx>
51 #include <svx/svdoutl.hxx>
52 using namespace svx::sidebar;
53 namespace sd {
54 
55 TYPEINIT1( FuOutlineBullet, FuPoor );
56 
57 /*************************************************************************
58 |*
59 |* Konstruktor
60 |*
61 \************************************************************************/
62 
63 FuOutlineBullet::FuOutlineBullet(ViewShell* pViewShell, ::sd::Window* pWindow,
64 								 ::sd::View* pView, SdDrawDocument* pDoc,
65 								 SfxRequest& rReq)
66 	   : FuPoor(pViewShell, pWindow, pView, pDoc, rReq)
67 {
68 }
69 
70 FunctionReference FuOutlineBullet::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
71 {
72 	FunctionReference xFunc( new FuOutlineBullet( pViewSh, pWin, pView, pDoc, rReq ) );
73 	xFunc->DoExecute(rReq);
74 	return xFunc;
75 }
76 
77 void FuOutlineBullet::DoExecute( SfxRequest& rReq )
78 {
79 	sal_uInt16 nSId = rReq.GetSlot();
80 	if (nSId == FN_SVX_SET_BULLET){
81 		SetCurrentBullet(rReq);
82 		return;
83 	}
84 	else if (nSId == FN_SVX_SET_NUMBER){
85 		SetCurrentNumbering(rReq);
86 		return;
87 	}
88 
89 	const SfxItemSet* pArgs = rReq.GetArgs();
90 
91 	if( !pArgs )
92 	{
93 		// ItemSet fuer Dialog fuellen
94 		SfxItemSet aEditAttr( mpDoc->GetPool() );
95 		mpView->GetAttributes( aEditAttr );
96 
97 		SfxItemSet aNewAttr( mpViewShell->GetPool(),
98 							 EE_ITEMS_START, EE_ITEMS_END );
99 		aNewAttr.Put( aEditAttr, sal_False );
100 
101 		// Dialog hochfahren und ausfuehren
102 		SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
103 		SfxAbstractTabDialog* pDlg = pFact ? pFact->CreateSdOutlineBulletTabDlg( NULL, &aNewAttr, mpView ) : 0;
104 		if( pDlg )
105 		{
106 			sal_uInt16 nResult = pDlg->Execute();
107 
108 			switch( nResult )
109 			{
110 				case RET_OK:
111 				{
112 					SfxItemSet aSet( *pDlg->GetOutputItemSet() );
113 
114 	                OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
115 
116 	                std::auto_ptr< OutlineViewModelChangeGuard > aGuard;
117 
118 	                if (mpView->ISA(OutlineView))
119 	                {
120 		                pOLV = static_cast<OutlineView*>(mpView)
121                             ->GetViewByWindow(mpViewShell->GetActiveWindow());
122 
123 		                aGuard.reset( new OutlineViewModelChangeGuard( static_cast<OutlineView&>(*mpView) ) );
124 	                }
125 
126                     if( pOLV )
127                         pOLV->EnableBullets();
128 
129 					rReq.Done( aSet );
130 					pArgs = rReq.GetArgs();
131 				}
132 				break;
133 
134 				default:
135 				{
136 					delete pDlg;
137 					return;
138 				}
139 			}
140 
141 			delete pDlg;
142 		}
143 	}
144 
145 	// nicht direkt an pOlView, damit SdDrawView::SetAttributes
146 	// Aenderungen auf der Masterpage abfangen und in eine
147 	// Vorlage umleiten kann
148 	mpView->SetAttributes(*pArgs);
149 
150 /* #i35937#
151 	// evtl. Betroffene Felder invalidieren
152 	mpViewShell->Invalidate( FN_NUM_BULLET_ON );
153 */
154 }
155 
156 void FuOutlineBullet::SetCurrentNumbering(SfxRequest& rReq)
157 {
158 	if (!mpDoc || !mpView)
159 		return;
160 
161 	SfxItemSet aEditAttr( mpDoc->GetPool() );
162 	mpView->GetAttributes( aEditAttr );
163 
164 	SfxItemSet aNewAttr( mpViewShell->GetPool(),
165 							 EE_ITEMS_START, EE_ITEMS_END );
166 	aNewAttr.Put( aEditAttr, sal_False );
167 
168 	SfxItemSet aSetAttr( mpViewShell->GetPool(),
169 							 EE_ITEMS_START, EE_ITEMS_END );
170 
171 	//Init bullet level in "Customize" tab page in bullet dialog in master page view
172 	if( mpView && mpViewShell && mpViewShell->ISA(DrawViewShell)
173 		&& ((DrawViewShell *)mpViewShell)->GetEditMode() == EM_MASTERPAGE )
174 	{
175 		SdrObject* pObj = mpView->GetTextEditObject();
176 		if( pObj && pObj->GetObjIdentifier() == OBJ_OUTLINETEXT )
177 		{
178 			sal_uInt16 nLevel = mpView->GetSelectionLevel();
179 			if( nLevel != 0xFFFF )
180 			{
181 
182 				SfxItemSet aStoreSet( aNewAttr );
183 				aNewAttr.ClearItem();
184 				//extend range
185 				aNewAttr.MergeRange( SID_PARAM_NUM_PRESET, SID_PARAM_CUR_NUM_LEVEL );
186 				aNewAttr.Put( aStoreSet );
187 				//put current level user selected
188 				aNewAttr.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
189 			}
190 		}
191 	}
192 	//End of add
193 
194 	sal_uInt16 nActNumLvl = (sal_uInt16)0xFFFF;
195 	SvxNumRule* pNumRule = NULL;
196 	const SfxPoolItem* pTmpItem=NULL;
197 	sal_uInt32 nNumItemId = SID_ATTR_NUMBERING_RULE;
198 
199 	if(SFX_ITEM_SET == aNewAttr.GetItemState(SID_PARAM_CUR_NUM_LEVEL, sal_False, &pTmpItem))
200 		nActNumLvl = ((const SfxUInt16Item*)pTmpItem)->GetValue();
201 
202 	pTmpItem=GetNumBulletItem(aNewAttr, nNumItemId);
203 
204 	if (pTmpItem)
205 		pNumRule = new SvxNumRule(*((SvxNumBulletItem*)pTmpItem)->GetNumRule());
206 
207 	SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, FN_SVX_SET_NUMBER , sal_False );
208 	if (pItem && pNumRule)
209 	{
210 		sal_uInt16 nIdx = pItem->GetValue();
211 		// If the nIdx is (sal_uInt16)0xFFFF, means set bullet status to on/off
212 		// And the bullet default status is 1.
213 		bool bBulletSwitch = false;
214         sal_Bool isRemoveNum =false;
215 		if( nIdx == (sal_uInt16)0xFFFF )
216 		{
217 			nIdx = 1;
218 			bBulletSwitch = true;
219 		}
220 		if (nIdx == DEFAULT_NONE)
221 		{
222 			bBulletSwitch = false;
223 			isRemoveNum = true;
224 		}
225 		nIdx--;
226 
227 		NBOTypeMgrBase* pNumbering = NBOutlineTypeMgrFact::CreateInstance(eNBOType::NUMBERING);
228 		if ( pNumbering )
229 		{
230 			//Sym3_2508, set unit attribute to NB Manager
231 			pNumbering->SetItems(&aNewAttr);
232 			SvxNumRule aTmpRule( *pNumRule );
233 			pNumbering->ApplyNumRule(aTmpRule,nIdx,nActNumLvl);
234 			sal_uInt16 nMask = 1;
235 			for(sal_uInt16 i = 0; i < pNumRule->GetLevelCount(); i++)
236 			{
237 				if(nActNumLvl & nMask)
238 				{
239 					SvxNumberFormat aFmt(aTmpRule.GetLevel(i));
240 					pNumRule->SetLevel(i, aFmt);
241 				}
242 				nMask <<= 1 ;
243 			}
244 			aSetAttr.Put(SvxNumBulletItem( *pNumRule ), nNumItemId);
245 			OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
246 
247 	       	 std::auto_ptr< OutlineViewModelChangeGuard > aGuard;
248 
249 	        	if (mpView->ISA(OutlineView))
250 	        	{
251 			        pOLV = static_cast<OutlineView*>(mpView)
252 	                    ->GetViewByWindow(mpViewShell->GetActiveWindow());
253 
254 			        aGuard.reset( new OutlineViewModelChangeGuard( static_cast<OutlineView&>(*mpView) ) );
255 	        	}
256 
257             		SdrOutliner* pOwner = mpView->GetTextEditOutliner();
258 			bool bMasterView = false;
259 
260 			DrawViewShell* pDrawViewShell = static_cast< DrawViewShell* >(mpViewShell);
261 
262 			if ( pOwner && pDrawViewShell && pDrawViewShell->GetEditMode() == EM_MASTERPAGE )
263 				bMasterView = !pOwner->IsInUndo() && pOwner->IsUndoEnabled();
264 
265 			if( bMasterView )
266 			{
267 				pOwner->UndoActionStart( OLUNDO_ATTR );
268 				pOLV->ToggleBullets( bBulletSwitch, sal_False, bMasterView, pNumRule,isRemoveNum);
269 				mpView->SetAttributes(aSetAttr); //Modify for Sym2_3151
270 				pOwner->UndoActionEnd( OLUNDO_ATTR );
271 			}
272 			else if( pOLV )
273 				pOLV->ToggleBullets( bBulletSwitch, sal_False, bMasterView, pNumRule ,isRemoveNum);
274 			else
275 			{
276 				sal_Bool bInMasterView = pDrawViewShell && pDrawViewShell->GetEditMode() == EM_MASTERPAGE;
277 				SdrModel* pSdrModel = mpView->GetModel();
278 				sal_Bool bModelUndoEnabled = pSdrModel ? pSdrModel->IsUndoEnabled() : sal_False;
279 				if (bInMasterView && bModelUndoEnabled)
280 				{
281 					pSdrModel->BegUndo();
282 				}
283 				mpView->ToggleMarkedObjectsBullets(bBulletSwitch, sal_False, bInMasterView, pNumRule,isRemoveNum);
284 				if (bInMasterView)
285 				{
286 					mpView->SetAttributes(aSetAttr);
287 				}
288 				if (bInMasterView && bModelUndoEnabled)
289 				{
290 					pSdrModel->EndUndo();
291 				}
292 			}
293 		}
294 		//End
295 	}
296 	delete pNumRule;
297 	rReq.Done();
298 }
299 
300 void FuOutlineBullet::SetCurrentBullet(SfxRequest& rReq)
301 {
302 	if (!mpDoc || !mpView)
303 		return;
304 
305 	SfxItemSet aEditAttr( mpDoc->GetPool() );
306 	mpView->GetAttributes( aEditAttr );
307 
308 	SfxItemSet aNewAttr( mpViewShell->GetPool(),
309 							 EE_ITEMS_START, EE_ITEMS_END );
310 	aNewAttr.Put( aEditAttr, sal_False );
311 
312 	//Add for Sym2_3151, should add new attributes in an empty item set, then use this item set as parameter in SetAttributes()
313 	SfxItemSet aSetAttr( mpViewShell->GetPool(),
314 							 EE_ITEMS_START, EE_ITEMS_END );
315 
316 	//Init bullet level in "Customize" tab page in bullet dialog in master page view
317 	if( mpView && mpViewShell && mpViewShell->ISA(DrawViewShell)
318 		&& ((DrawViewShell *)mpViewShell)->GetEditMode() == EM_MASTERPAGE )
319 	{
320 		SdrObject* pObj = mpView->GetTextEditObject();
321 		if( pObj && pObj->GetObjIdentifier() == OBJ_OUTLINETEXT )
322 		{
323 			sal_uInt16 nLevel = mpView->GetSelectionLevel();
324 			if( nLevel != 0xFFFF )
325 			{
326 				//aNewAttr.MergeRange( SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL );
327 				//aNewAttr.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
328 				//save the itemset value
329 				SfxItemSet aStoreSet( aNewAttr );
330 				aNewAttr.ClearItem();
331 				//extend range
332 				aNewAttr.MergeRange( SID_PARAM_NUM_PRESET, SID_PARAM_CUR_NUM_LEVEL );
333 				aNewAttr.Put( aStoreSet );
334 				//put current level user selected
335 				aNewAttr.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
336 			}
337 		}
338 	}
339 	//End of add
340 
341 	sal_uInt16 nActNumLvl = (sal_uInt16)0xFFFF;
342 	SvxNumRule* pNumRule = NULL;
343 	const SfxPoolItem* pTmpItem=NULL;
344 	sal_uInt32 nNumItemId = SID_ATTR_NUMBERING_RULE;
345 
346 	if(SFX_ITEM_SET == aNewAttr.GetItemState(SID_PARAM_CUR_NUM_LEVEL, sal_False, &pTmpItem))
347 		nActNumLvl = ((const SfxUInt16Item*)pTmpItem)->GetValue();
348 
349 	pTmpItem=GetNumBulletItem(aNewAttr, nNumItemId);
350 
351 	if (pTmpItem)
352 		pNumRule = new SvxNumRule(*((SvxNumBulletItem*)pTmpItem)->GetNumRule());
353 
354 	SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, FN_SVX_SET_BULLET , sal_False );
355 	if (pItem && pNumRule)
356 	{
357 		sal_uInt16 nIdx = pItem->GetValue();
358 		// If the nIdx is (sal_uInt16)0xFFFF, means set bullet status to on/off
359 		// And the bullet default status is 2.
360 		bool bBulletSwitch = false;
361         sal_Bool isRemoveNum =false;
362 		if( nIdx == (sal_uInt16)0xFFFF )
363 		{
364 			nIdx = 1;
365 			bBulletSwitch = true;
366 		}
367 		if (nIdx == DEFAULT_NONE)
368 		{
369 			bBulletSwitch = false;
370 			isRemoveNum = true;
371 		}
372 
373 		nIdx--;
374 		//Modified for Numbering&Bullets Dialog UX Enh(Story 992) by chengjh,2011.8.7
375 
376 		NBOTypeMgrBase* pBullets = NBOutlineTypeMgrFact::CreateInstance(eNBOType::MIXBULLETS);
377 		if ( pBullets )
378 		{
379 			//Sym3_2508, set unit attribute to NB Manager
380 			pBullets->SetItems(&aNewAttr);
381 			SvxNumRule aTmpRule( *pNumRule );
382 			//Sym3_3423 Always apply the "." if wants a default numbering rule
383 			if (bBulletSwitch==true && nIdx==0) //want to reset bullet
384 			{
385 				pBullets->ApplyNumRule(aTmpRule,nIdx,nActNumLvl,true);
386 			}
387 			else {
388 				pBullets->ApplyNumRule(aTmpRule,nIdx,nActNumLvl);
389 			}
390 			sal_uInt16 nMask = 1;
391 			for(sal_uInt16 i = 0; i < pNumRule->GetLevelCount(); i++)
392 			{
393 				if(nActNumLvl & nMask)
394 				{
395 					SvxNumberFormat aFmt(aTmpRule.GetLevel(i));
396 					pNumRule->SetLevel(i, aFmt);
397 				}
398 				nMask <<= 1;
399 			}
400 			aSetAttr.Put(SvxNumBulletItem( *pNumRule ), nNumItemId);
401 
402 			OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
403 
404 	        	std::auto_ptr< OutlineViewModelChangeGuard > aGuard;
405 
406 		       if (mpView->ISA(OutlineView))
407 		       {
408 			        pOLV = static_cast<OutlineView*>(mpView)
409 	                    ->GetViewByWindow(mpViewShell->GetActiveWindow());
410 
411 			        aGuard.reset( new OutlineViewModelChangeGuard( static_cast<OutlineView&>(*mpView) ) );
412 		       }
413 
414 			SdrOutliner* pOwner = mpView->GetTextEditOutliner();
415 			bool bMasterView = false;
416 
417 			DrawViewShell* pDrawViewShell = static_cast< DrawViewShell* >(mpViewShell);
418 
419 			if ( pOwner && pDrawViewShell && pDrawViewShell->GetEditMode() == EM_MASTERPAGE )
420 				bMasterView = !pOwner->IsInUndo() && pOwner->IsUndoEnabled();
421 
422 			if( bMasterView )
423 			{
424 				pOwner->UndoActionStart( OLUNDO_ATTR );
425 				pOLV->ToggleBullets( bBulletSwitch, sal_True, bMasterView, pNumRule, isRemoveNum );
426 				mpView->SetAttributes(aSetAttr); //Modify for Sym2_3151
427 				pOwner->UndoActionEnd( OLUNDO_ATTR );
428 			}
429 			else if( pOLV )
430 				pOLV->ToggleBullets( bBulletSwitch, sal_True, bMasterView, pNumRule, isRemoveNum );
431 			else
432 			{
433 				sal_Bool bInMasterView = pDrawViewShell && pDrawViewShell->GetEditMode() == EM_MASTERPAGE;
434 				SdrModel* pSdrModel = mpView->GetModel();
435 				sal_Bool bModelUndoEnabled = pSdrModel ? pSdrModel->IsUndoEnabled() : sal_False;
436 				if (bInMasterView && bModelUndoEnabled)
437 				{
438 					pSdrModel->BegUndo();
439 				}
440 				mpView->ToggleMarkedObjectsBullets(bBulletSwitch, sal_True, bInMasterView, pNumRule, isRemoveNum );
441 				if (bInMasterView)
442 				{
443 					mpView->SetAttributes(aSetAttr);
444 				}
445 				if (bInMasterView && bModelUndoEnabled)
446 				{
447 					pSdrModel->EndUndo();
448 				}
449 			}
450 		}
451 		//End
452 	}
453 	delete pNumRule;
454 	rReq.Done();
455 }
456 
457 const SfxPoolItem* FuOutlineBullet::GetNumBulletItem(SfxItemSet& aNewAttr, sal_uInt32& nNumItemId)
458 {
459 	//SvxNumBulletItem* pRetItem = NULL;
460 	const SfxPoolItem* pTmpItem = NULL;
461 
462 	if(aNewAttr.GetItemState(nNumItemId, sal_False, &pTmpItem) == SFX_ITEM_SET)
463 	{
464 		return pTmpItem;
465 	}
466 	else
467 	{
468 		nNumItemId = aNewAttr.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
469 		SfxItemState eState = aNewAttr.GetItemState(nNumItemId, sal_False, &pTmpItem);
470 		if (eState == SFX_ITEM_SET)
471 			return pTmpItem;
472 		else
473 		{
474 			sal_Bool bOutliner = sal_False;
475 			sal_Bool bTitle = sal_False;
476 
477 			if( mpView )
478      		{
479 				const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
480 				const sal_uInt32 nCount = rMarkList.GetMarkCount();
481 
482 				for(sal_uInt32 nNum = 0; nNum < nCount; nNum++)
483 				{
484 					SdrObject* pObj = rMarkList.GetMark(nNum)->GetMarkedSdrObj();
485 					if( pObj->GetObjInventor() == SdrInventor )
486 					{
487 						switch(pObj->GetObjIdentifier())
488 						{
489 						case OBJ_TITLETEXT:
490 							bTitle = sal_True;
491 							break;
492 						case OBJ_OUTLINETEXT:
493 							bOutliner = sal_True;
494 							break;
495 						}
496 					}
497 				}
498 			}
499 
500 			const SvxNumBulletItem *pItem = NULL;
501 			if(bOutliner)
502 			{
503 				SfxStyleSheetBasePool* pSSPool = mpView->GetDocSh()->GetStyleSheetPool();
504 				String aStyleName((SdResId((sal_uInt16)STR_LAYOUT_OUTLINE)));
505 				aStyleName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " 1" ) );
506 				SfxStyleSheetBase* pFirstStyleSheet = pSSPool->Find( aStyleName, SD_STYLE_FAMILY_PSEUDO);
507 				if( pFirstStyleSheet )
508 					pFirstStyleSheet->GetItemSet().GetItemState(EE_PARA_NUMBULLET, sal_False, (const SfxPoolItem**)&pItem);
509 			}
510 
511 			if( pItem == NULL )
512 				pItem = (SvxNumBulletItem*) aNewAttr.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET);
513 
514 			//DBG_ASSERT( pItem, "Kein EE_PARA_NUMBULLET im Pool! [CL]" );
515 
516 			aNewAttr.Put(*pItem, EE_PARA_NUMBULLET);
517 
518 			if(bTitle && aNewAttr.GetItemState(EE_PARA_NUMBULLET,sal_True) == SFX_ITEM_ON )
519 			{
520 				SvxNumBulletItem* pItem = (SvxNumBulletItem*)aNewAttr.GetItem(EE_PARA_NUMBULLET,sal_True);
521 				SvxNumRule* pRule = pItem->GetNumRule();
522 				if(pRule)
523 				{
524 					SvxNumRule aNewRule( *pRule );
525 					aNewRule.SetFeatureFlag( NUM_NO_NUMBERS, sal_True );
526 
527 					SvxNumBulletItem aNewItem( aNewRule, EE_PARA_NUMBULLET );
528 					aNewAttr.Put(aNewItem);
529 				}
530 			}
531 
532 			SfxItemState eState = aNewAttr.GetItemState(nNumItemId, sal_False, &pTmpItem);
533 			if (eState == SFX_ITEM_SET)
534 				return pTmpItem;
535 
536 		}
537 		//DBG_ASSERT(eState == SFX_ITEM_SET, "kein Item gefunden!")
538 	}
539 	return pTmpItem;
540 }
541 
542 } // end of namespace sd
543