1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5efeef26fSAndrew Rist * distributed with this work for additional information
6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist * software distributed under the License is distributed on an
15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17efeef26fSAndrew Rist * specific language governing permissions and limitations
18efeef26fSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20efeef26fSAndrew Rist *************************************************************/
21efeef26fSAndrew Rist
22efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <hintids.hxx>
29cdf0e10cSrcweir #include <vcl/msgbox.hxx>
30cdf0e10cSrcweir #include <sfx2/request.hxx>
31cdf0e10cSrcweir #include <svl/eitem.hxx>
32cdf0e10cSrcweir #include <svl/stritem.hxx>
33cdf0e10cSrcweir #include <editeng/numitem.hxx>
34cdf0e10cSrcweir #include <editeng/brshitem.hxx>
35cdf0e10cSrcweir #include <numrule.hxx>
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include "cmdid.h"
38cdf0e10cSrcweir #include "wrtsh.hxx"
39cdf0e10cSrcweir #include "view.hxx"
40cdf0e10cSrcweir #include "viewopt.hxx"
41cdf0e10cSrcweir #include "wdocsh.hxx"
42cdf0e10cSrcweir #include "textsh.hxx"
43cdf0e10cSrcweir #include "uiitems.hxx"
44cdf0e10cSrcweir #include "swabstdlg.hxx"
45cdf0e10cSrcweir #include <globals.hrc>
46cdf0e10cSrcweir #include <sfx2/tabdlg.hxx>
47766ce4d0SZheng Fan #include <svx/nbdtmg.hxx>
48766ce4d0SZheng Fan #include <svx/nbdtmgfact.hxx>
491ff378efSZheng Fan #include <sfx2/viewfrm.hxx>
501ff378efSZheng Fan #include <sfx2/bindings.hxx>
51cdf0e10cSrcweir
ExecEnterNum(SfxRequest & rReq)52cdf0e10cSrcweir void SwTextShell::ExecEnterNum(SfxRequest &rReq)
53cdf0e10cSrcweir {
54cdf0e10cSrcweir //wg. Aufzeichnung schon vor dem evtl. Shellwechsel
55cdf0e10cSrcweir switch(rReq.GetSlot())
56cdf0e10cSrcweir {
57cdf0e10cSrcweir case FN_NUM_NUMBERING_ON:
58cdf0e10cSrcweir {
591ff378efSZheng Fan GetShell().StartAllAction();
60cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , sal_False );
611ff378efSZheng Fan sal_Bool bMode = !GetShell().SelectionHasNumber(); // #i29560#
62cdf0e10cSrcweir if ( pItem )
63cdf0e10cSrcweir bMode = pItem->GetValue();
64cdf0e10cSrcweir else
65cdf0e10cSrcweir rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
66cdf0e10cSrcweir
671ff378efSZheng Fan if ( bMode != (GetShell().SelectionHasNumber()) ) // #i29560#
68cdf0e10cSrcweir {
69cdf0e10cSrcweir rReq.Done();
70cdf0e10cSrcweir if( bMode )
71cdf0e10cSrcweir GetShell().NumOn();
72cdf0e10cSrcweir else
73cdf0e10cSrcweir GetShell().NumOrBulletOff(); // #i29560#
74cdf0e10cSrcweir }
751ff378efSZheng Fan sal_Bool bNewResult = GetShell().SelectionHasNumber();
761ff378efSZheng Fan if (bNewResult!=bMode) {
771ff378efSZheng Fan SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
781ff378efSZheng Fan SfxBoolItem aItem(FN_NUM_NUMBERING_ON,!bNewResult);
791ff378efSZheng Fan rBindings.SetState(aItem);
801ff378efSZheng Fan SfxBoolItem aNewItem(FN_NUM_NUMBERING_ON,bNewResult);
811ff378efSZheng Fan rBindings.SetState(aNewItem);
821ff378efSZheng Fan }
831ff378efSZheng Fan GetShell().EndAllAction();
84cdf0e10cSrcweir }
85cdf0e10cSrcweir break;
86cdf0e10cSrcweir case FN_NUM_BULLET_ON:
87cdf0e10cSrcweir {
881ff378efSZheng Fan GetShell().StartAllAction();
89cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , sal_False );
901ff378efSZheng Fan sal_Bool bMode = !GetShell().SelectionHasBullet(); // #i29560#
91cdf0e10cSrcweir if ( pItem )
92cdf0e10cSrcweir bMode = pItem->GetValue();
93cdf0e10cSrcweir else
94cdf0e10cSrcweir rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
95cdf0e10cSrcweir
961ff378efSZheng Fan if ( bMode != (GetShell().SelectionHasBullet()) ) // #i29560#
97cdf0e10cSrcweir {
98cdf0e10cSrcweir rReq.Done();
99cdf0e10cSrcweir if( bMode )
100cdf0e10cSrcweir GetShell().BulletOn();
101cdf0e10cSrcweir else
102cdf0e10cSrcweir GetShell().NumOrBulletOff(); // #i29560#
103cdf0e10cSrcweir }
1041ff378efSZheng Fan sal_Bool bNewResult = GetShell().SelectionHasBullet();
1051ff378efSZheng Fan if (bNewResult!=bMode) {
1061ff378efSZheng Fan SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
1071ff378efSZheng Fan SfxBoolItem aItem(FN_NUM_BULLET_ON,!bNewResult);
1081ff378efSZheng Fan rBindings.SetState(aItem);
1091ff378efSZheng Fan SfxBoolItem aNewItem(FN_NUM_BULLET_ON,bNewResult);
1101ff378efSZheng Fan rBindings.SetState(aNewItem);
1111ff378efSZheng Fan }
1121ff378efSZheng Fan GetShell().EndAllAction();
113cdf0e10cSrcweir }
114cdf0e10cSrcweir break;
115*34760e49SOliver-Rainer Wittmann
116cdf0e10cSrcweir case FN_NUMBER_BULLETS:
117766ce4d0SZheng Fan case SID_OUTLINE_BULLET:
118cdf0e10cSrcweir {
119cdf0e10cSrcweir SfxItemSet aSet( GetPool(),
120cdf0e10cSrcweir SID_HTML_MODE, SID_HTML_MODE,
121cdf0e10cSrcweir SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
122cdf0e10cSrcweir 0 );
123cdf0e10cSrcweir SwDocShell* pDocSh = GetView().GetDocShell();
124*34760e49SOliver-Rainer Wittmann const bool bHtml = 0 != PTR_CAST( SwWebDocShell, pDocSh );
125*34760e49SOliver-Rainer Wittmann const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
126*34760e49SOliver-Rainer Wittmann if ( pNumRuleAtCurrentSelection != NULL )
127cdf0e10cSrcweir {
128*34760e49SOliver-Rainer Wittmann SvxNumRule aRule = pNumRuleAtCurrentSelection->MakeSvxNumRule();
129cdf0e10cSrcweir
130cdf0e10cSrcweir //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
131cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++ )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir SvxNumberFormat aFmt( aRule.GetLevel( i ) );
134cdf0e10cSrcweir if ( SVX_NUM_BITMAP == aFmt.GetNumberingType() )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir const SvxBrushItem* pBrush = aFmt.GetBrush();
137*34760e49SOliver-Rainer Wittmann const String* pLinkStr = pBrush != NULL
138*34760e49SOliver-Rainer Wittmann ? pBrush->GetGraphicLink()
139*34760e49SOliver-Rainer Wittmann : NULL;
140*34760e49SOliver-Rainer Wittmann if ( pLinkStr != NULL && pLinkStr->Len() > 0 )
141*34760e49SOliver-Rainer Wittmann {
142cdf0e10cSrcweir aFmt.SetNumberingType( SvxExtNumType( SVX_NUM_BITMAP | LINK_TOKEN ) );
143*34760e49SOliver-Rainer Wittmann }
144cdf0e10cSrcweir aRule.SetLevel( i, aFmt, aRule.Get( i ) != 0 );
145cdf0e10cSrcweir }
146cdf0e10cSrcweir }
147cdf0e10cSrcweir if ( bHtml )
148cdf0e10cSrcweir aRule.SetFeatureFlag( NUM_ENABLE_EMBEDDED_BMP, sal_False );
149cdf0e10cSrcweir
150cdf0e10cSrcweir aSet.Put( SvxNumBulletItem( aRule ) );
151cdf0e10cSrcweir ASSERT( GetShell().GetNumLevel() < MAXLEVEL,
152cdf0e10cSrcweir "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect -> please inform OD." );
153cdf0e10cSrcweir sal_uInt16 nLevel = GetShell().GetNumLevel();
154cdf0e10cSrcweir if ( nLevel < MAXLEVEL )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir nLevel = 1 << nLevel;
157cdf0e10cSrcweir aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
158cdf0e10cSrcweir }
159cdf0e10cSrcweir }
160cdf0e10cSrcweir else
161cdf0e10cSrcweir {
162cdf0e10cSrcweir SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
163cdf0e10cSrcweir numfunc::GetDefaultPositionAndSpaceMode() );
164cdf0e10cSrcweir SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
165cdf0e10cSrcweir const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
166cdf0e10cSrcweir
167cdf0e10cSrcweir if ( bHtml || bRightToLeft )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir for ( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
172cdf0e10cSrcweir if ( n && bHtml )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir // 1/2" fuer HTML
175cdf0e10cSrcweir aFmt.SetLSpace( 720 );
176cdf0e10cSrcweir aFmt.SetAbsLSpace( n * 720 );
177cdf0e10cSrcweir }
178*34760e49SOliver-Rainer Wittmann // Default alignment for numbering/bullet should be rtl in rtl paragraph:
179cdf0e10cSrcweir if ( bRightToLeft )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
182cdf0e10cSrcweir }
183cdf0e10cSrcweir aSvxRule.SetLevel( n, aFmt, sal_False );
184cdf0e10cSrcweir }
185cdf0e10cSrcweir aSvxRule.SetFeatureFlag( NUM_ENABLE_EMBEDDED_BMP, sal_False );
186cdf0e10cSrcweir }
187cdf0e10cSrcweir aSet.Put( SvxNumBulletItem( aSvxRule ) );
188cdf0e10cSrcweir }
189cdf0e10cSrcweir
190cdf0e10cSrcweir aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET, sal_False ) );
191cdf0e10cSrcweir
192cdf0e10cSrcweir // vor dem Dialog wird der HtmlMode an der DocShell versenkt
193cdf0e10cSrcweir pDocSh->PutItem( SfxUInt16Item( SID_HTML_MODE, ::GetHtmlMode( pDocSh ) ) );
194cdf0e10cSrcweir
195cdf0e10cSrcweir SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
196cdf0e10cSrcweir DBG_ASSERT( pFact, "Dialogdiet fail!" );
197*34760e49SOliver-Rainer Wittmann SfxAbstractTabDialog* pDlg =
198*34760e49SOliver-Rainer Wittmann pFact->CreateSwTabDialog( DLG_SVXTEST_NUM_BULLET, GetView().GetWindow(), &aSet, GetShell() );
199cdf0e10cSrcweir DBG_ASSERT(pDlg, "Dialogdiet fail!");
200*34760e49SOliver-Rainer Wittmann const sal_uInt16 nRet = pDlg->Execute();
201cdf0e10cSrcweir const SfxPoolItem* pItem;
202cdf0e10cSrcweir if ( RET_OK == nRet )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir if ( SFX_ITEM_SET == pDlg->GetOutputItemSet()->GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ) )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir rReq.AppendItem( *pItem );
207cdf0e10cSrcweir rReq.Done();
208cdf0e10cSrcweir SvxNumRule* pSetRule = ( (SvxNumBulletItem*) pItem )->GetNumRule();
209cdf0e10cSrcweir pSetRule->UnLinkGraphics();
210*34760e49SOliver-Rainer Wittmann SwNumRule aSetRule( pNumRuleAtCurrentSelection != NULL
211*34760e49SOliver-Rainer Wittmann ? pNumRuleAtCurrentSelection->GetName()
212cdf0e10cSrcweir : GetShell().GetUniqueNumRuleName(),
213cdf0e10cSrcweir numfunc::GetDefaultPositionAndSpaceMode() );
214cdf0e10cSrcweir aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc() );
215cdf0e10cSrcweir aSetRule.SetAutoRule( sal_True );
216cdf0e10cSrcweir // No start of new list, if an existing list style is edited.
217cdf0e10cSrcweir // Otherwise start a new list.
218*34760e49SOliver-Rainer Wittmann const bool bCreateList = ( pNumRuleAtCurrentSelection == NULL );
219cdf0e10cSrcweir GetShell().SetCurNumRule( aSetRule, bCreateList );
220cdf0e10cSrcweir }
221cdf0e10cSrcweir // wenn der Dialog mit OK verlassen wurde, aber nichts ausgewaehlt
222cdf0e10cSrcweir // wurde dann muss die Numerierung zumindest eingeschaltet werden,
223cdf0e10cSrcweir // wenn sie das noch nicht ist
224*34760e49SOliver-Rainer Wittmann else if ( pNumRuleAtCurrentSelection == NULL
225*34760e49SOliver-Rainer Wittmann && SFX_ITEM_SET == aSet.GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ) )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir rReq.AppendItem( *pItem );
228cdf0e10cSrcweir rReq.Done();
229cdf0e10cSrcweir SvxNumRule* pSetRule = ( (SvxNumBulletItem*) pItem )->GetNumRule();
230*34760e49SOliver-Rainer Wittmann SwNumRule aSetRule(
231*34760e49SOliver-Rainer Wittmann GetShell().GetUniqueNumRuleName(),
232cdf0e10cSrcweir numfunc::GetDefaultPositionAndSpaceMode() );
233cdf0e10cSrcweir aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc() );
234cdf0e10cSrcweir aSetRule.SetAutoRule( sal_True );
235cdf0e10cSrcweir // start new list
236cdf0e10cSrcweir GetShell().SetCurNumRule( aSetRule, true );
237cdf0e10cSrcweir }
238cdf0e10cSrcweir }
239cdf0e10cSrcweir else if ( RET_USER == nRet )
240cdf0e10cSrcweir GetShell().DelNumRules();
241cdf0e10cSrcweir
242cdf0e10cSrcweir delete pDlg;
243cdf0e10cSrcweir }
244cdf0e10cSrcweir break;
245*34760e49SOliver-Rainer Wittmann
246cdf0e10cSrcweir default:
247*34760e49SOliver-Rainer Wittmann ASSERT( sal_False, "wrong Dispatcher" );
248cdf0e10cSrcweir return;
249cdf0e10cSrcweir }
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
252*34760e49SOliver-Rainer Wittmann
ExecSetNumber(SfxRequest & rReq)253766ce4d0SZheng Fan void SwTextShell::ExecSetNumber(SfxRequest &rReq)
254766ce4d0SZheng Fan {
255*34760e49SOliver-Rainer Wittmann const sal_uInt16 nSlot = rReq.GetSlot();
256*34760e49SOliver-Rainer Wittmann switch ( nSlot )
257766ce4d0SZheng Fan {
258*34760e49SOliver-Rainer Wittmann case FN_SVX_SET_NUMBER:
259*34760e49SOliver-Rainer Wittmann case FN_SVX_SET_BULLET:
260766ce4d0SZheng Fan {
261*34760e49SOliver-Rainer Wittmann SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, nSlot, sal_False );
262*34760e49SOliver-Rainer Wittmann if ( pItem != NULL )
263766ce4d0SZheng Fan {
264*34760e49SOliver-Rainer Wittmann const sal_uInt16 nChoosenItemIdx = pItem->GetValue();
265*34760e49SOliver-Rainer Wittmann if ( nChoosenItemIdx == DEFAULT_NONE )
266766ce4d0SZheng Fan {
267*34760e49SOliver-Rainer Wittmann GetShell().DelNumRules();
268766ce4d0SZheng Fan }
269*34760e49SOliver-Rainer Wittmann else
270*34760e49SOliver-Rainer Wittmann {
271*34760e49SOliver-Rainer Wittmann svx::sidebar::NBOTypeMgrBase* pNBOTypeMgr =
272*34760e49SOliver-Rainer Wittmann nSlot == FN_SVX_SET_NUMBER
273*34760e49SOliver-Rainer Wittmann ? svx::sidebar::NBOutlineTypeMgrFact::CreateInstance( svx::sidebar::eNBOType::NUMBERING )
274*34760e49SOliver-Rainer Wittmann : svx::sidebar::NBOutlineTypeMgrFact::CreateInstance( svx::sidebar::eNBOType::MIXBULLETS );
275*34760e49SOliver-Rainer Wittmann if ( pNBOTypeMgr != NULL )
276*34760e49SOliver-Rainer Wittmann {
277*34760e49SOliver-Rainer Wittmann const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
278766ce4d0SZheng Fan sal_uInt16 nActNumLvl = (sal_uInt16) 0xFFFF;
279*34760e49SOliver-Rainer Wittmann if ( pNumRuleAtCurrentSelection != NULL )
280766ce4d0SZheng Fan {
281766ce4d0SZheng Fan sal_uInt16 nLevel = GetShell().GetNumLevel();
282766ce4d0SZheng Fan if ( nLevel < MAXLEVEL )
283766ce4d0SZheng Fan {
284766ce4d0SZheng Fan nActNumLvl = 1 << nLevel;
285766ce4d0SZheng Fan }
286766ce4d0SZheng Fan }
287*34760e49SOliver-Rainer Wittmann SwNumRule aNewNumRule(
288*34760e49SOliver-Rainer Wittmann pNumRuleAtCurrentSelection != NULL ? pNumRuleAtCurrentSelection->GetName() : GetShell().GetUniqueNumRuleName(),
289766ce4d0SZheng Fan numfunc::GetDefaultPositionAndSpaceMode() );
290*34760e49SOliver-Rainer Wittmann SvxNumRule aNewSvxNumRule = pNumRuleAtCurrentSelection != NULL
291*34760e49SOliver-Rainer Wittmann ? pNumRuleAtCurrentSelection->MakeSvxNumRule()
292*34760e49SOliver-Rainer Wittmann : aNewNumRule.MakeSvxNumRule();
2930deba7fbSSteve Yin // set unit attribute to NB Manager
294*34760e49SOliver-Rainer Wittmann SfxItemSet aSet( GetPool(), SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL, 0 );
295*34760e49SOliver-Rainer Wittmann aSet.Put( SvxNumBulletItem( aNewSvxNumRule ) );
296*34760e49SOliver-Rainer Wittmann pNBOTypeMgr->SetItems( &aSet );
297*34760e49SOliver-Rainer Wittmann pNBOTypeMgr->ApplyNumRule( aNewSvxNumRule, nChoosenItemIdx - 1, nActNumLvl );
298766ce4d0SZheng Fan
299*34760e49SOliver-Rainer Wittmann aNewNumRule.SetSvxRule( aNewSvxNumRule, GetShell().GetDoc() );
300*34760e49SOliver-Rainer Wittmann aNewNumRule.SetAutoRule( sal_True );
301*34760e49SOliver-Rainer Wittmann const bool bCreateNewList = ( pNumRuleAtCurrentSelection == NULL );
302*34760e49SOliver-Rainer Wittmann GetShell().SetCurNumRule( aNewNumRule, bCreateNewList );
303766ce4d0SZheng Fan }
304766ce4d0SZheng Fan }
305766ce4d0SZheng Fan }
306766ce4d0SZheng Fan }
307766ce4d0SZheng Fan break;
308766ce4d0SZheng Fan
309*34760e49SOliver-Rainer Wittmann default:
310*34760e49SOliver-Rainer Wittmann ASSERT( sal_False, "wrong Dispatcher" );
311*34760e49SOliver-Rainer Wittmann return;
312766ce4d0SZheng Fan }
313766ce4d0SZheng Fan }
314