update credits
[LibreOffice.git] / sw / source / ui / shells / txtnum.cxx
blobf55e3f22fdaf860636ffecfcf344b53d1556d2fe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <hintids.hxx>
21 #include <vcl/msgbox.hxx>
22 #include <sfx2/request.hxx>
23 #include <svl/eitem.hxx>
24 #include <svl/stritem.hxx>
25 #include <editeng/numitem.hxx>
26 #include <editeng/brushitem.hxx>
27 #include <numrule.hxx>
29 #include "cmdid.h"
30 #include "wrtsh.hxx"
31 #include "view.hxx"
32 #include "viewopt.hxx"
33 #include "wdocsh.hxx"
34 #include "textsh.hxx"
35 #include "uiitems.hxx"
36 #include "swabstdlg.hxx"
37 #include <globals.hrc>
38 #include <sfx2/tabdlg.hxx>
39 #include <svx/nbdtmg.hxx>
40 #include <svx/nbdtmgfact.hxx>
41 #include <sfx2/viewfrm.hxx>
42 #include <sfx2/bindings.hxx>
43 using namespace svx::sidebar;
45 void SwTextShell::ExecEnterNum(SfxRequest &rReq)
47 //Because the record before any shell exchange.
48 switch(rReq.GetSlot())
50 case FN_NUM_NUMBERING_ON:
52 GetShell().StartAllAction();
53 SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , sal_False );
54 sal_Bool bMode = !GetShell().SelectionHasNumber(); // #i29560#
55 if ( pItem )
56 bMode = pItem->GetValue();
57 else
58 rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
60 if ( bMode != (GetShell().SelectionHasNumber()) ) // #i29560#
62 rReq.Done();
63 if( bMode )
64 GetShell().NumOn();
65 else
66 GetShell().NumOrBulletOff(); // #i29560#
68 sal_Bool bNewResult = GetShell().SelectionHasNumber();
69 if (bNewResult!=bMode) {
70 SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
71 SfxBoolItem aItem(FN_NUM_NUMBERING_ON,!bNewResult);
72 rBindings.SetState(aItem);
73 SfxBoolItem aNewItem(FN_NUM_NUMBERING_ON,bNewResult);
74 rBindings.SetState(aNewItem);
76 GetShell().EndAllAction();
78 break;
79 case FN_NUM_BULLET_ON:
81 GetShell().StartAllAction();
82 SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , sal_False );
83 sal_Bool bMode = !GetShell().SelectionHasBullet(); // #i29560#
84 if ( pItem )
85 bMode = pItem->GetValue();
86 else
87 rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
89 if ( bMode != (GetShell().SelectionHasBullet()) ) // #i29560#
91 rReq.Done();
92 if( bMode )
93 GetShell().BulletOn();
94 else
95 GetShell().NumOrBulletOff(); // #i29560#
97 sal_Bool bNewResult = GetShell().SelectionHasBullet();
98 if (bNewResult!=bMode) {
99 SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
100 SfxBoolItem aItem(FN_NUM_BULLET_ON,!bNewResult);
101 rBindings.SetState(aItem);
102 SfxBoolItem aNewItem(FN_NUM_BULLET_ON,bNewResult);
103 rBindings.SetState(aNewItem);
105 GetShell().EndAllAction();
107 break;
108 case FN_NUMBER_BULLETS:
109 case SID_OUTLINE_BULLET:
111 SfxItemSet aSet(GetPool(),
112 SID_HTML_MODE, SID_HTML_MODE,
113 SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
114 0 );
115 SwDocShell* pDocSh = GetView().GetDocShell();
116 bool bHtml = 0 != PTR_CAST(SwWebDocShell, pDocSh);
117 const SwNumRule* pCurRule = GetShell().GetCurNumRule();
118 if( pCurRule )
120 SvxNumRule aRule = pCurRule->MakeSvxNumRule();
122 //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
123 for(sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++)
125 SvxNumberFormat aFmt(aRule.GetLevel(i));
126 if(SVX_NUM_BITMAP == aFmt.GetNumberingType())
128 const SvxBrushItem* pBrush = aFmt.GetBrush();
129 const String* pLinkStr;
130 if(pBrush &&
131 0 != (pLinkStr = pBrush->GetGraphicLink()) &&
132 pLinkStr->Len())
133 aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
134 aRule.SetLevel(i, aFmt, aRule.Get(i) != 0);
137 if(bHtml)
138 aRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
140 aSet.Put(SvxNumBulletItem(aRule));
141 OSL_ENSURE( GetShell().GetNumLevel() < MAXLEVEL,
142 "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect -> please inform OD." );
143 sal_uInt16 nLevel = GetShell().GetNumLevel();
144 if( nLevel < MAXLEVEL )
146 nLevel = 1<<nLevel;
147 aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ));
150 else
152 SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
153 // #i89178#
154 numfunc::GetDefaultPositionAndSpaceMode() );
155 SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
156 const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
158 if( bHtml || bRightToLeft )
160 for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
162 SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
163 if ( n && bHtml )
165 // 1/2" for HTML
166 aFmt.SetLSpace(720);
167 aFmt.SetAbsLSpace(n * 720);
169 // #i38904# Default alignment for
170 // numbering/bullet should be rtl in rtl paragraph:
171 if ( bRightToLeft )
173 aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
175 aSvxRule.SetLevel( n, aFmt, sal_False );
177 aSvxRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
179 aSet.Put(SvxNumBulletItem(aSvxRule));
182 aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET,sal_False ));
184 // Before the dialogue of the HTML mode will be droped at the Docshell.
185 pDocSh->PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(pDocSh)));
187 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
188 OSL_ENSURE(pFact, "Dialogdiet fail!");
189 SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_SVXTEST_NUM_BULLET,
190 GetView().GetWindow(), &aSet, GetShell());
191 OSL_ENSURE(pDlg, "Dialogdiet fail!");
192 sal_uInt16 nRet = pDlg->Execute();
193 const SfxPoolItem* pItem;
194 if( RET_OK == nRet )
196 if( SFX_ITEM_SET == pDlg->GetOutputItemSet()->GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ))
198 rReq.AppendItem(*pItem);
199 rReq.Done();
200 SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
201 pSetRule->UnLinkGraphics();
202 SwNumRule aSetRule( pCurRule
203 ? pCurRule->GetName()
204 : GetShell().GetUniqueNumRuleName(),
205 // #i89178#
206 numfunc::GetDefaultPositionAndSpaceMode() );
207 aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc());
208 aSetRule.SetAutoRule( sal_True );
209 // No start of new list, if an existing list style is edited.
210 // Otherwise start a new list.
211 const bool bCreateList = (pCurRule == 0);
212 GetShell().SetCurNumRule( aSetRule, bCreateList );
214 // If the Dialog was leaved with OK but nothing was chosen then the
215 // numbering must be at least activated, if it is not already.
216 else if( !pCurRule && SFX_ITEM_SET == aSet.GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ))
218 rReq.AppendItem( *pItem );
219 rReq.Done();
220 SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
221 SwNumRule aSetRule( GetShell().GetUniqueNumRuleName(),
222 // #i89178#
223 numfunc::GetDefaultPositionAndSpaceMode() );
224 aSetRule.SetSvxRule(*pSetRule, GetShell().GetDoc());
225 aSetRule.SetAutoRule( sal_True );
226 // start new list
227 GetShell().SetCurNumRule( aSetRule, true );
230 else if(RET_USER == nRet)
231 GetShell().DelNumRules();
233 delete pDlg;
235 break;
236 default:
237 OSL_FAIL("wrong dispatcher");
238 return;
242 void SwTextShell::ExecSetNumber(SfxRequest &rReq)
244 SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
245 // #i89178#
246 numfunc::GetDefaultPositionAndSpaceMode() );
248 SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
249 const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
251 if( bRightToLeft )
253 for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
255 SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
256 /* if ( n && bHtml )
258 // 1/2" for HTML
259 aFmt.SetLSpace(720);
260 aFmt.SetAbsLSpace(n * 720);
262 // #i38904# Default alignment for
263 // numbering/bullet should be rtl in rtl paragraph:
264 if ( bRightToLeft )
266 aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
268 aSvxRule.SetLevel( n, aFmt, sal_False );
270 aSvxRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
273 const SwNumRule* pCurRule = GetShell().GetCurNumRule();
274 sal_uInt16 nActNumLvl = (sal_uInt16)0xFFFF;
275 if( pCurRule )
277 sal_uInt16 nLevel = GetShell().GetNumLevel();
278 if( nLevel < MAXLEVEL )
280 nActNumLvl = 1<<nLevel;
283 aSvxRule = pCurRule->MakeSvxNumRule();
285 //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
286 for(sal_uInt16 i = 0; i < aSvxRule.GetLevelCount(); i++)
288 SvxNumberFormat aFmt(aSvxRule.GetLevel(i));
289 if(SVX_NUM_BITMAP == aFmt.GetNumberingType())
291 const SvxBrushItem* pBrush = aFmt.GetBrush();
292 const String* pLinkStr;
293 if(pBrush &&
294 0 != (pLinkStr = pBrush->GetGraphicLink()) &&
295 pLinkStr->Len())
296 aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
297 aSvxRule.SetLevel(i, aFmt, aSvxRule.Get(i) != 0);
303 switch(rReq.GetSlot())
305 case FN_SVX_SET_NUMBER:
307 SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, FN_SVX_SET_NUMBER , sal_False );
308 if (pItem)
310 sal_uInt16 nIdx = pItem->GetValue();
311 if (nIdx==DEFAULT_NONE) {
312 GetShell().DelNumRules();
313 break;
315 --nIdx;
317 NBOTypeMgrBase* pNumbering = NBOutlineTypeMgrFact::CreateInstance(eNBOType::NUMBERING);
318 if ( pNumbering )
320 SwNumRule aTmpRule( GetShell().GetUniqueNumRuleName(),
321 numfunc::GetDefaultPositionAndSpaceMode() );
323 SvxNumRule aTempRule = aTmpRule.MakeSvxNumRule();
324 //Sym3_2508, set unit attribute to NB Manager
325 SfxItemSet aSet(GetPool(),
326 SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
327 0 );
328 aSet.Put(SvxNumBulletItem(aTempRule));
329 pNumbering->SetItems(&aSet);
330 pNumbering->ApplyNumRule(aTempRule,nIdx,nActNumLvl);
332 sal_uInt16 nMask = 1;
333 for(sal_uInt16 i = 0; i < aSvxRule.GetLevelCount(); i++)
335 if(nActNumLvl & nMask)
337 SvxNumberFormat aFmt(aTempRule.GetLevel(i));
338 aSvxRule.SetLevel(i, aFmt);
340 nMask <<= 1 ;
343 aSvxRule.UnLinkGraphics();
344 SwNumRule aSetRule( pCurRule
345 ? pCurRule->GetName()
346 : GetShell().GetUniqueNumRuleName(),
347 numfunc::GetDefaultPositionAndSpaceMode() );
348 aSetRule.SetSvxRule( aSvxRule, GetShell().GetDoc());
350 aSetRule.SetAutoRule( sal_True );
351 const bool bCreateList = (pCurRule == 0);
352 GetShell().SetCurNumRule( aSetRule, bCreateList );
354 //End
356 break;
358 case FN_SVX_SET_BULLET:
360 SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, FN_SVX_SET_BULLET , sal_False );
361 if (pItem)
363 sal_uInt16 nIdx = pItem->GetValue();
364 if (nIdx==DEFAULT_NONE) {
365 GetShell().DelNumRules();
366 break;
368 nIdx--;
370 NBOTypeMgrBase* pBullets = NBOutlineTypeMgrFact::CreateInstance(eNBOType::MIXBULLETS);
371 if ( pBullets )
373 SwNumRule aTmpRule( GetShell().GetUniqueNumRuleName(),
374 numfunc::GetDefaultPositionAndSpaceMode() );
376 SvxNumRule aTempRule = aTmpRule.MakeSvxNumRule();
377 //Sym3_2508, set unit attribute to NB Manager
378 SfxItemSet aSet(GetPool(),
379 SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
380 0 );
381 aSet.Put(SvxNumBulletItem(aTempRule));
382 pBullets->SetItems(&aSet);
384 //SvxNumRule aTempRule( 0, 10, false );
385 pBullets->ApplyNumRule(aTempRule,nIdx,nActNumLvl);
386 sal_uInt16 nMask = 1;
387 for(sal_uInt16 i = 0; i < aSvxRule.GetLevelCount(); i++)
389 if(nActNumLvl & nMask)
391 SvxNumberFormat aFmt(aTempRule.GetLevel(i));
392 aSvxRule.SetLevel(i, aFmt);
394 nMask <<= 1;
396 aSvxRule.UnLinkGraphics();
398 SwNumRule aSetRule( pCurRule
399 ? pCurRule->GetName()
400 : GetShell().GetUniqueNumRuleName(),
401 numfunc::GetDefaultPositionAndSpaceMode() );
403 aSetRule.SetSvxRule( aSvxRule, GetShell().GetDoc());
405 aSetRule.SetAutoRule( sal_True );
406 const bool bCreateList = (pCurRule == 0);
407 GetShell().SetCurNumRule( aSetRule, bCreateList );
409 //End
413 break;
417 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */