xref: /aoo41x/main/sw/source/ui/shells/txtnum.cxx (revision efeef26f)
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 
50 void SwTextShell::ExecEnterNum(SfxRequest &rReq)
51 {
52 	//wg. Aufzeichnung schon vor dem evtl. Shellwechsel
53 	switch(rReq.GetSlot())
54 	{
55 	case FN_NUM_NUMBERING_ON:
56 	{
57         SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , sal_False );
58         sal_Bool bMode = !GetShell().HasNumber(); // #i29560#
59         if ( pItem )
60             bMode = pItem->GetValue();
61         else
62             rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
63 
64         if ( bMode != (GetShell().HasNumber()) ) // #i29560#
65         {
66             rReq.Done();
67             if( bMode )
68                 GetShell().NumOn();
69             else
70                 GetShell().NumOrBulletOff(); // #i29560#
71         }
72 	}
73 	break;
74 	case FN_NUM_BULLET_ON:
75 	{
76         SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , sal_False );
77         sal_Bool bMode = !GetShell().HasBullet(); // #i29560#
78         if ( pItem )
79             bMode = pItem->GetValue();
80         else
81             rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
82 
83         if ( bMode != (GetShell().HasBullet()) ) // #i29560#
84         {
85             rReq.Done();
86             if( bMode )
87                 GetShell().BulletOn();
88             else
89                 GetShell().NumOrBulletOff(); // #i29560#
90         }
91 	}
92 	break;
93 	case FN_NUMBER_BULLETS:
94 	{
95         // --> OD 2008-02-29 #refactorlists#
96 //        // per default sal_True, damit die Schleife im Dialog richtig arbeitet!
97 //        sal_Bool bHasChild = sal_True;
98         // <--
99 		SfxItemSet aSet(GetPool(),
100 				SID_HTML_MODE, SID_HTML_MODE,
101 				SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
102 				0 );
103 		SwDocShell* pDocSh = GetView().GetDocShell();
104 		sal_Bool bHtml = 0 != PTR_CAST(SwWebDocShell, pDocSh);
105 		const SwNumRule* pCurRule = GetShell().GetCurNumRule();
106 		if( pCurRule )
107 		{
108 			SvxNumRule aRule = pCurRule->MakeSvxNumRule();
109 
110 			//convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
111 			for(sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++)
112 			{
113 				SvxNumberFormat aFmt(aRule.GetLevel(i));
114 				if(SVX_NUM_BITMAP == aFmt.GetNumberingType())
115 				{
116 					const SvxBrushItem* pBrush = aFmt.GetBrush();
117 					const String* pLinkStr;
118 					if(pBrush &&
119 						0 != (pLinkStr = pBrush->GetGraphicLink()) &&
120 							pLinkStr->Len())
121 						aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
122 					aRule.SetLevel(i, aFmt, aRule.Get(i) != 0);
123 				}
124 			}
125 			if(bHtml)
126 				aRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
127 
128 			aSet.Put(SvxNumBulletItem(aRule));
129             // --> OD 2008-02-29 #refactorlists# - removed <bHasChild>
130             ASSERT( GetShell().GetNumLevel() < MAXLEVEL,
131                     "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect -> please inform OD." );
132             sal_uInt16 nLevel = GetShell().GetNumLevel();
133             // <--
134 			if( nLevel < MAXLEVEL )
135 			{
136 				nLevel = 1<<nLevel;
137 				aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ));
138 			}
139 		}
140 		else
141 		{
142             // --> OD 2008-02-11 #newlistlevelattrs#
143             SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
144                              // --> OD 2008-06-06 #i89178#
145                              numfunc::GetDefaultPositionAndSpaceMode() );
146                              // <--
147             // <--
148 			SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
149             const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
150 
151             if( bHtml || bRightToLeft )
152 			{
153                 for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
154 				{
155 					SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
156                     if ( n && bHtml )
157                     {
158                         // 1/2" fuer HTML
159                         aFmt.SetLSpace(720);
160                         aFmt.SetAbsLSpace(n * 720);
161                     }
162                     // --> FME 2005-01-21 #i38904#  Default alignment for
163                     // numbering/bullet should be rtl in rtl paragraph:
164                     if ( bRightToLeft )
165                     {
166                         aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
167                     }
168                     // <--
169                     aSvxRule.SetLevel( n, aFmt, sal_False );
170 				}
171 				aSvxRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
172 			}
173 			aSet.Put(SvxNumBulletItem(aSvxRule));
174 		}
175 
176 		aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET,sal_False ));
177 
178 		// vor dem Dialog wird der HtmlMode an der DocShell versenkt
179 		pDocSh->PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(pDocSh)));
180 
181 		SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
182         DBG_ASSERT(pFact, "Dialogdiet fail!");
183         SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_SVXTEST_NUM_BULLET,
184 														GetView().GetWindow(), &aSet, GetShell());
185         DBG_ASSERT(pDlg, "Dialogdiet fail!");
186 		sal_uInt16 nRet = pDlg->Execute();
187 		const SfxPoolItem* pItem;
188 		if( RET_OK == nRet )
189 		{
190 			if( SFX_ITEM_SET == pDlg->GetOutputItemSet()->GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ))
191 			{
192 				rReq.AppendItem(*pItem);
193 				rReq.Done();
194 				SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
195 				pSetRule->UnLinkGraphics();
196                 // --> OD 2008-02-11 #newlistlevelattrs#
197 				SwNumRule aSetRule( pCurRule
198 										? pCurRule->GetName()
199                                         : GetShell().GetUniqueNumRuleName(),
200                                     // --> OD 2008-06-06 #i89178#
201                                     numfunc::GetDefaultPositionAndSpaceMode() );
202                                     // <--
203                 // <--
204 				aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc());
205 				aSetRule.SetAutoRule( sal_True );
206                 // --> OD 2008-03-17 #refactorlists#
207                 // No start of new list, if an existing list style is edited.
208                 // Otherwise start a new list.
209                 const bool bCreateList = (pCurRule == 0);
210                 GetShell().SetCurNumRule( aSetRule, bCreateList );
211                 // <--
212 			}
213 			// wenn der Dialog mit OK verlassen wurde, aber nichts ausgewaehlt
214 			// wurde dann muss die Numerierung zumindest eingeschaltet werden,
215 			// wenn sie das noch nicht ist
216 			else if( !pCurRule && SFX_ITEM_SET == aSet.GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ))
217 			{
218 				rReq.AppendItem( *pItem );
219 				rReq.Done();
220 				SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
221                 // --> OD 2008-02-11 #newlistlevelattrs#
222                 SwNumRule aSetRule( GetShell().GetUniqueNumRuleName(),
223                                     // --> OD 2008-06-06 #i89178#
224                                     numfunc::GetDefaultPositionAndSpaceMode() );
225                                     // <--
226                 // <--
227 				aSetRule.SetSvxRule(*pSetRule, GetShell().GetDoc());
228 				aSetRule.SetAutoRule( sal_True );
229                 // --> OD 2008-03-17 #refactorlists#
230                 // start new list
231                 GetShell().SetCurNumRule( aSetRule, true );
232                 // <--
233 			}
234 		}
235 		else if(RET_USER == nRet)
236 			GetShell().DelNumRules();
237 
238 		delete pDlg;
239 	}
240 	break;
241 	default:
242 		ASSERT(sal_False,  falscher Dispatcher);
243 		return;
244 	}
245 }
246 
247 
248