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