xref: /aoo4110/main/sw/source/ui/shells/txtnum.cxx (revision b1cdbd2c)
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_sw.hxx"
26 
27 
28 #include <hintids.hxx>
29 #ifndef _MSGBOX_HXX //autogen
30 #include <vcl/msgbox.hxx>
31 #endif
32 #include <sfx2/request.hxx>
33 #include <svl/eitem.hxx>
34 #include <svl/stritem.hxx>
35 #include <editeng/numitem.hxx>
36 #include <editeng/brshitem.hxx>
37 #include <numrule.hxx>
38 
39 #include "cmdid.h"
40 #include "wrtsh.hxx"
41 #include "view.hxx"
42 #include "viewopt.hxx"
43 #include "wdocsh.hxx"
44 #include "textsh.hxx"
45 #include "uiitems.hxx"
46 #include "swabstdlg.hxx"
47 #include <globals.hrc>
48 #include <sfx2/tabdlg.hxx>
49 #include <svx/nbdtmg.hxx>
50 #include <svx/nbdtmgfact.hxx>
51 #include <sfx2/viewfrm.hxx>
52 #include <sfx2/bindings.hxx>
53 using namespace svx::sidebar;
54 
ExecEnterNum(SfxRequest & rReq)55 void SwTextShell::ExecEnterNum(SfxRequest &rReq)
56 {
57 	//wg. Aufzeichnung schon vor dem evtl. Shellwechsel
58 	switch(rReq.GetSlot())
59 	{
60 	case FN_NUM_NUMBERING_ON:
61 	{
62 		GetShell().StartAllAction();
63 		SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , sal_False );
64 		sal_Bool bMode = !GetShell().SelectionHasNumber(); // #i29560#
65 		if ( pItem )
66 			bMode = pItem->GetValue();
67 		else
68 			rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
69 
70 		if ( bMode != (GetShell().SelectionHasNumber()) ) // #i29560#
71 		{
72 			rReq.Done();
73 			if( bMode )
74 				GetShell().NumOn();
75 			else
76 				GetShell().NumOrBulletOff(); // #i29560#
77 		}
78 		sal_Bool bNewResult = GetShell().SelectionHasNumber();
79 		if (bNewResult!=bMode) {
80 			SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
81 			SfxBoolItem aItem(FN_NUM_NUMBERING_ON,!bNewResult);
82 			rBindings.SetState(aItem);
83 			SfxBoolItem aNewItem(FN_NUM_NUMBERING_ON,bNewResult);
84 			rBindings.SetState(aNewItem);
85 		}
86 		GetShell().EndAllAction();
87 	}
88 	break;
89 	case FN_NUM_BULLET_ON:
90 	{
91 		GetShell().StartAllAction();
92 		SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , sal_False );
93 		sal_Bool bMode = !GetShell().SelectionHasBullet(); // #i29560#
94 		if ( pItem )
95 			bMode = pItem->GetValue();
96 		else
97 			rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
98 
99 		if ( bMode != (GetShell().SelectionHasBullet()) ) // #i29560#
100 		{
101 			rReq.Done();
102 			if( bMode )
103 				GetShell().BulletOn();
104 			else
105 				GetShell().NumOrBulletOff(); // #i29560#
106 		}
107 		sal_Bool bNewResult = GetShell().SelectionHasBullet();
108 		if (bNewResult!=bMode) {
109 			SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
110 			SfxBoolItem aItem(FN_NUM_BULLET_ON,!bNewResult);
111 			rBindings.SetState(aItem);
112 			SfxBoolItem aNewItem(FN_NUM_BULLET_ON,bNewResult);
113 			rBindings.SetState(aNewItem);
114 		}
115 		GetShell().EndAllAction();
116 	}
117 	break;
118 	case FN_NUMBER_BULLETS:
119 	case SID_OUTLINE_BULLET:
120 	{
121         // --> OD 2008-02-29 #refactorlists#
122 //        // per default sal_True, damit die Schleife im Dialog richtig arbeitet!
123 //        sal_Bool bHasChild = sal_True;
124         // <--
125 		SfxItemSet aSet(GetPool(),
126 				SID_HTML_MODE, SID_HTML_MODE,
127 				SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
128 				0 );
129 		SwDocShell* pDocSh = GetView().GetDocShell();
130 		sal_Bool bHtml = 0 != PTR_CAST(SwWebDocShell, pDocSh);
131 		const SwNumRule* pCurRule = GetShell().GetCurNumRule();
132 		if( pCurRule )
133 		{
134 			SvxNumRule aRule = pCurRule->MakeSvxNumRule();
135 
136 			//convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
137 			for(sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++)
138 			{
139 				SvxNumberFormat aFmt(aRule.GetLevel(i));
140 				if(SVX_NUM_BITMAP == aFmt.GetNumberingType())
141 				{
142 					const SvxBrushItem* pBrush = aFmt.GetBrush();
143 					const String* pLinkStr;
144 					if(pBrush &&
145 						0 != (pLinkStr = pBrush->GetGraphicLink()) &&
146 							pLinkStr->Len())
147 						aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
148 					aRule.SetLevel(i, aFmt, aRule.Get(i) != 0);
149 				}
150 			}
151 			if(bHtml)
152 				aRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
153 
154 			aSet.Put(SvxNumBulletItem(aRule));
155             // --> OD 2008-02-29 #refactorlists# - removed <bHasChild>
156             ASSERT( GetShell().GetNumLevel() < MAXLEVEL,
157                     "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect -> please inform OD." );
158             sal_uInt16 nLevel = GetShell().GetNumLevel();
159             // <--
160 			if( nLevel < MAXLEVEL )
161 			{
162 				nLevel = 1<<nLevel;
163 				aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ));
164 			}
165 		}
166 		else
167 		{
168             // --> OD 2008-02-11 #newlistlevelattrs#
169             SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
170                              // --> OD 2008-06-06 #i89178#
171                              numfunc::GetDefaultPositionAndSpaceMode() );
172                              // <--
173             // <--
174 			SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
175             const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
176 
177             if( bHtml || bRightToLeft )
178 			{
179                 for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
180 				{
181 					SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
182                     if ( n && bHtml )
183                     {
184                         // 1/2" fuer HTML
185                         aFmt.SetLSpace(720);
186                         aFmt.SetAbsLSpace(n * 720);
187                     }
188                     // --> FME 2005-01-21 #i38904#  Default alignment for
189                     // numbering/bullet should be rtl in rtl paragraph:
190                     if ( bRightToLeft )
191                     {
192                         aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
193                     }
194                     // <--
195                     aSvxRule.SetLevel( n, aFmt, sal_False );
196 				}
197 				aSvxRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
198 			}
199 			aSet.Put(SvxNumBulletItem(aSvxRule));
200 		}
201 
202 		aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET,sal_False ));
203 
204 		// vor dem Dialog wird der HtmlMode an der DocShell versenkt
205 		pDocSh->PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(pDocSh)));
206 
207 		SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
208         DBG_ASSERT(pFact, "Dialogdiet fail!");
209         SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_SVXTEST_NUM_BULLET,
210 														GetView().GetWindow(), &aSet, GetShell());
211         DBG_ASSERT(pDlg, "Dialogdiet fail!");
212 		sal_uInt16 nRet = pDlg->Execute();
213 		const SfxPoolItem* pItem;
214 		if( RET_OK == nRet )
215 		{
216 			if( SFX_ITEM_SET == pDlg->GetOutputItemSet()->GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ))
217 			{
218 				rReq.AppendItem(*pItem);
219 				rReq.Done();
220 				SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
221 				pSetRule->UnLinkGraphics();
222                 // --> OD 2008-02-11 #newlistlevelattrs#
223 				SwNumRule aSetRule( pCurRule
224 										? pCurRule->GetName()
225                                         : GetShell().GetUniqueNumRuleName(),
226                                     // --> OD 2008-06-06 #i89178#
227                                     numfunc::GetDefaultPositionAndSpaceMode() );
228                                     // <--
229                 // <--
230 				aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc());
231 				aSetRule.SetAutoRule( sal_True );
232                 // --> OD 2008-03-17 #refactorlists#
233                 // No start of new list, if an existing list style is edited.
234                 // Otherwise start a new list.
235                 const bool bCreateList = (pCurRule == 0);
236                 GetShell().SetCurNumRule( aSetRule, bCreateList );
237                 // <--
238 			}
239 			// wenn der Dialog mit OK verlassen wurde, aber nichts ausgewaehlt
240 			// wurde dann muss die Numerierung zumindest eingeschaltet werden,
241 			// wenn sie das noch nicht ist
242 			else if( !pCurRule && SFX_ITEM_SET == aSet.GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ))
243 			{
244 				rReq.AppendItem( *pItem );
245 				rReq.Done();
246 				SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
247                 // --> OD 2008-02-11 #newlistlevelattrs#
248                 SwNumRule aSetRule( GetShell().GetUniqueNumRuleName(),
249                                     // --> OD 2008-06-06 #i89178#
250                                     numfunc::GetDefaultPositionAndSpaceMode() );
251                                     // <--
252                 // <--
253 				aSetRule.SetSvxRule(*pSetRule, GetShell().GetDoc());
254 				aSetRule.SetAutoRule( sal_True );
255                 // --> OD 2008-03-17 #refactorlists#
256                 // start new list
257                 GetShell().SetCurNumRule( aSetRule, true );
258                 // <--
259 			}
260 		}
261 		else if(RET_USER == nRet)
262 			GetShell().DelNumRules();
263 
264 		delete pDlg;
265 	}
266 	break;
267 	default:
268 		ASSERT(sal_False,  falscher Dispatcher);
269 		return;
270 	}
271 }
272 
ExecSetNumber(SfxRequest & rReq)273 void SwTextShell::ExecSetNumber(SfxRequest &rReq)
274 {
275 	SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
276 						 // --> OD 2008-06-06 #i89178#
277 						 numfunc::GetDefaultPositionAndSpaceMode() );
278 						 // <--
279 
280 	SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
281     const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
282 
283     if( bRightToLeft )
284 	{
285         for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
286 		{
287 			SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
288            /* if ( n && bHtml )
289             {
290                 // 1/2" fuer HTML
291                 aFmt.SetLSpace(720);
292                 aFmt.SetAbsLSpace(n * 720);
293             }*/
294             // --> FME 2005-01-21 #i38904#  Default alignment for
295             // numbering/bullet should be rtl in rtl paragraph:
296             if ( bRightToLeft )
297             {
298                 aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
299             }
300             // <--
301             aSvxRule.SetLevel( n, aFmt, sal_False );
302 		}
303 		aSvxRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
304 	}
305 
306 	const SwNumRule* pCurRule = GetShell().GetCurNumRule();
307 	sal_uInt16		nActNumLvl = (sal_uInt16)0xFFFF;
308 	if( pCurRule )
309 	{
310 		sal_uInt16 nLevel = GetShell().GetNumLevel();
311      	if( nLevel < MAXLEVEL )
312 		{
313 			nActNumLvl = 1<<nLevel;
314 		}
315 
316 		aSvxRule = pCurRule->MakeSvxNumRule();
317 
318 		//convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
319 		for(sal_uInt16 i = 0; i < aSvxRule.GetLevelCount(); i++)
320 		{
321 			SvxNumberFormat aFmt(aSvxRule.GetLevel(i));
322 			if(SVX_NUM_BITMAP == aFmt.GetNumberingType())
323 			{
324 				const SvxBrushItem* pBrush = aFmt.GetBrush();
325 				const String* pLinkStr;
326 				if(pBrush &&
327 					0 != (pLinkStr = pBrush->GetGraphicLink()) &&
328 						pLinkStr->Len())
329 					aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
330 				aSvxRule.SetLevel(i, aFmt, aSvxRule.Get(i) != 0);
331 			}
332 		}
333 	}
334 
335 
336 	switch(rReq.GetSlot())
337 	{
338 	case FN_SVX_SET_NUMBER:
339 		{
340 			SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, FN_SVX_SET_NUMBER , sal_False );
341 			if (pItem)
342 			{
343 				sal_uInt16 nIdx = pItem->GetValue();
344 				if (nIdx==DEFAULT_NONE) {
345 					GetShell().DelNumRules();
346 					break;
347 				}
348 				--nIdx;
349 
350 				NBOTypeMgrBase* pNumbering = NBOutlineTypeMgrFact::CreateInstance(eNBOType::NUMBERING);
351 				if ( pNumbering )
352 				{
353 					SwNumRule aTmpRule( GetShell().GetUniqueNumRuleName(),
354 						 numfunc::GetDefaultPositionAndSpaceMode() );
355 
356 					SvxNumRule aTempRule = aTmpRule.MakeSvxNumRule();
357 					// set unit attribute to NB Manager
358 					SfxItemSet aSet(GetPool(),
359 							SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
360 							0 );
361 					aSet.Put(SvxNumBulletItem(aTempRule));
362 					pNumbering->SetItems(&aSet);
363 					pNumbering->ApplyNumRule(aTempRule,nIdx,nActNumLvl);
364 
365 					sal_uInt16 nMask = 1;
366 					for(sal_uInt16 i = 0; i < aSvxRule.GetLevelCount(); i++)
367 					{
368 						if(nActNumLvl & nMask)
369 						{
370 							SvxNumberFormat aFmt(aTempRule.GetLevel(i));
371 							aSvxRule.SetLevel(i, aFmt);
372 						}
373 						nMask <<= 1 ;
374 					}
375 
376 					aSvxRule.UnLinkGraphics();
377 					SwNumRule aSetRule( pCurRule
378 											? pCurRule->GetName()
379 											: GetShell().GetUniqueNumRuleName(),
380 										numfunc::GetDefaultPositionAndSpaceMode() );
381 					aSetRule.SetSvxRule( aSvxRule, GetShell().GetDoc());
382 
383 					aSetRule.SetAutoRule( sal_True );
384 					const bool bCreateList = (pCurRule == 0);
385 					GetShell().SetCurNumRule( aSetRule, bCreateList );
386 				}
387 				//End
388 			}
389 			break;
390 		}
391 	case FN_SVX_SET_BULLET:
392 		{
393 			SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, FN_SVX_SET_BULLET , sal_False );
394 			if (pItem)
395 			{
396 				sal_uInt16 nIdx = pItem->GetValue();
397 				if (nIdx==DEFAULT_NONE) {
398 					GetShell().DelNumRules();
399 					break;
400 				}
401 				nIdx--;
402 
403 				NBOTypeMgrBase* pBullets = NBOutlineTypeMgrFact::CreateInstance(eNBOType::MIXBULLETS);
404 				if ( pBullets )
405 				{
406 					SwNumRule aTmpRule( GetShell().GetUniqueNumRuleName(),
407 						 numfunc::GetDefaultPositionAndSpaceMode() );
408 
409 					SvxNumRule aTempRule = aTmpRule.MakeSvxNumRule();
410 					// set unit attribute to NB Manager
411 					SfxItemSet aSet(GetPool(),
412 							SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
413 							0 );
414 					aSet.Put(SvxNumBulletItem(aTempRule));
415 					pBullets->SetItems(&aSet);
416 
417 					//SvxNumRule aTempRule( 0, 10, false );
418 					pBullets->ApplyNumRule(aTempRule,nIdx,nActNumLvl);
419 					sal_uInt16 nMask = 1;
420 					for(sal_uInt16 i = 0; i < aSvxRule.GetLevelCount(); i++)
421 					{
422 						if(nActNumLvl & nMask)
423 						{
424 							SvxNumberFormat aFmt(aTempRule.GetLevel(i));
425 							aSvxRule.SetLevel(i, aFmt);
426 						}
427 						nMask <<= 1;
428 					}
429 					aSvxRule.UnLinkGraphics();
430 
431 					SwNumRule aSetRule( pCurRule
432 											? pCurRule->GetName()
433 											: GetShell().GetUniqueNumRuleName(),
434 										numfunc::GetDefaultPositionAndSpaceMode() );
435 
436 					aSetRule.SetSvxRule( aSvxRule, GetShell().GetDoc());
437 
438 					aSetRule.SetAutoRule( sal_True );
439 					const bool bCreateList = (pCurRule == 0);
440 					GetShell().SetCurNumRule( aSetRule, bCreateList );
441 				}
442 				//End
443 			}
444 
445 		}
446 		break;
447 	}
448 }
449