xref: /aoo42x/main/sw/source/ui/shells/txtnum.cxx (revision 34760e49)
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 #include <vcl/msgbox.hxx>
30 #include <sfx2/request.hxx>
31 #include <svl/eitem.hxx>
32 #include <svl/stritem.hxx>
33 #include <editeng/numitem.hxx>
34 #include <editeng/brshitem.hxx>
35 #include <numrule.hxx>
36 
37 #include "cmdid.h"
38 #include "wrtsh.hxx"
39 #include "view.hxx"
40 #include "viewopt.hxx"
41 #include "wdocsh.hxx"
42 #include "textsh.hxx"
43 #include "uiitems.hxx"
44 #include "swabstdlg.hxx"
45 #include <globals.hrc>
46 #include <sfx2/tabdlg.hxx>
47 #include <svx/nbdtmg.hxx>
48 #include <svx/nbdtmgfact.hxx>
49 #include <sfx2/viewfrm.hxx>
50 #include <sfx2/bindings.hxx>
51 
ExecEnterNum(SfxRequest & rReq)52 void SwTextShell::ExecEnterNum(SfxRequest &rReq)
53 {
54 	//wg. Aufzeichnung schon vor dem evtl. Shellwechsel
55 	switch(rReq.GetSlot())
56 	{
57 	case FN_NUM_NUMBERING_ON:
58 	{
59 		GetShell().StartAllAction();
60 		SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , sal_False );
61 		sal_Bool bMode = !GetShell().SelectionHasNumber(); // #i29560#
62 		if ( pItem )
63 			bMode = pItem->GetValue();
64 		else
65 			rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
66 
67 		if ( bMode != (GetShell().SelectionHasNumber()) ) // #i29560#
68 		{
69 			rReq.Done();
70 			if( bMode )
71 				GetShell().NumOn();
72 			else
73 				GetShell().NumOrBulletOff(); // #i29560#
74 		}
75 		sal_Bool bNewResult = GetShell().SelectionHasNumber();
76 		if (bNewResult!=bMode) {
77 			SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
78 			SfxBoolItem aItem(FN_NUM_NUMBERING_ON,!bNewResult);
79 			rBindings.SetState(aItem);
80 			SfxBoolItem aNewItem(FN_NUM_NUMBERING_ON,bNewResult);
81 			rBindings.SetState(aNewItem);
82 		}
83 		GetShell().EndAllAction();
84 	}
85 	break;
86 	case FN_NUM_BULLET_ON:
87 	{
88 		GetShell().StartAllAction();
89 		SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , sal_False );
90 		sal_Bool bMode = !GetShell().SelectionHasBullet(); // #i29560#
91 		if ( pItem )
92 			bMode = pItem->GetValue();
93 		else
94 			rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
95 
96 		if ( bMode != (GetShell().SelectionHasBullet()) ) // #i29560#
97 		{
98 			rReq.Done();
99 			if( bMode )
100 				GetShell().BulletOn();
101 			else
102 				GetShell().NumOrBulletOff(); // #i29560#
103 		}
104 		sal_Bool bNewResult = GetShell().SelectionHasBullet();
105 		if (bNewResult!=bMode) {
106 			SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
107 			SfxBoolItem aItem(FN_NUM_BULLET_ON,!bNewResult);
108 			rBindings.SetState(aItem);
109 			SfxBoolItem aNewItem(FN_NUM_BULLET_ON,bNewResult);
110 			rBindings.SetState(aNewItem);
111 		}
112 		GetShell().EndAllAction();
113 	}
114 	break;
115 
116     case FN_NUMBER_BULLETS:
117     case SID_OUTLINE_BULLET:
118     {
119         SfxItemSet aSet( GetPool(),
120                          SID_HTML_MODE, SID_HTML_MODE,
121                          SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
122                          0 );
123         SwDocShell* pDocSh = GetView().GetDocShell();
124         const bool bHtml = 0 != PTR_CAST( SwWebDocShell, pDocSh );
125         const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
126         if ( pNumRuleAtCurrentSelection != NULL )
127         {
128             SvxNumRule aRule = pNumRuleAtCurrentSelection->MakeSvxNumRule();
129 
130             //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
131             for ( sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++ )
132             {
133                 SvxNumberFormat aFmt( aRule.GetLevel( i ) );
134                 if ( SVX_NUM_BITMAP == aFmt.GetNumberingType() )
135                 {
136                     const SvxBrushItem* pBrush = aFmt.GetBrush();
137                     const String* pLinkStr = pBrush != NULL
138                                              ? pBrush->GetGraphicLink()
139                                              : NULL;
140                     if ( pLinkStr != NULL && pLinkStr->Len() > 0 )
141                     {
142                         aFmt.SetNumberingType( SvxExtNumType( SVX_NUM_BITMAP | LINK_TOKEN ) );
143                     }
144                     aRule.SetLevel( i, aFmt, aRule.Get( i ) != 0 );
145                 }
146             }
147             if ( bHtml )
148                 aRule.SetFeatureFlag( NUM_ENABLE_EMBEDDED_BMP, sal_False );
149 
150             aSet.Put( SvxNumBulletItem( aRule ) );
151             ASSERT( GetShell().GetNumLevel() < MAXLEVEL,
152                     "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect -> please inform OD." );
153             sal_uInt16 nLevel = GetShell().GetNumLevel();
154             if ( nLevel < MAXLEVEL )
155             {
156                 nLevel = 1 << nLevel;
157                 aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
158             }
159         }
160         else
161         {
162             SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
163                              numfunc::GetDefaultPositionAndSpaceMode() );
164             SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
165             const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
166 
167             if ( bHtml || bRightToLeft )
168             {
169                 for ( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
170                 {
171                     SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
172                     if ( n && bHtml )
173                     {
174                         // 1/2" fuer HTML
175                         aFmt.SetLSpace( 720 );
176                         aFmt.SetAbsLSpace( n * 720 );
177                     }
178                     // Default alignment for numbering/bullet should be rtl in rtl paragraph:
179                     if ( bRightToLeft )
180                     {
181                         aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
182                     }
183                     aSvxRule.SetLevel( n, aFmt, sal_False );
184                 }
185                 aSvxRule.SetFeatureFlag( NUM_ENABLE_EMBEDDED_BMP, sal_False );
186             }
187             aSet.Put( SvxNumBulletItem( aSvxRule ) );
188         }
189 
190         aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET, sal_False ) );
191 
192         // vor dem Dialog wird der HtmlMode an der DocShell versenkt
193         pDocSh->PutItem( SfxUInt16Item( SID_HTML_MODE, ::GetHtmlMode( pDocSh ) ) );
194 
195         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
196         DBG_ASSERT( pFact, "Dialogdiet fail!" );
197         SfxAbstractTabDialog* pDlg =
198             pFact->CreateSwTabDialog( DLG_SVXTEST_NUM_BULLET, GetView().GetWindow(), &aSet, GetShell() );
199         DBG_ASSERT(pDlg, "Dialogdiet fail!");
200         const sal_uInt16 nRet = pDlg->Execute();
201         const SfxPoolItem* pItem;
202         if ( RET_OK == nRet )
203         {
204             if ( SFX_ITEM_SET == pDlg->GetOutputItemSet()->GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ) )
205             {
206                 rReq.AppendItem( *pItem );
207                 rReq.Done();
208                 SvxNumRule* pSetRule = ( (SvxNumBulletItem*) pItem )->GetNumRule();
209                 pSetRule->UnLinkGraphics();
210                 SwNumRule aSetRule( pNumRuleAtCurrentSelection != NULL
211                                     ? pNumRuleAtCurrentSelection->GetName()
212                                     : GetShell().GetUniqueNumRuleName(),
213                     numfunc::GetDefaultPositionAndSpaceMode() );
214                 aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc() );
215                 aSetRule.SetAutoRule( sal_True );
216                 // No start of new list, if an existing list style is edited.
217                 // Otherwise start a new list.
218                 const bool bCreateList = ( pNumRuleAtCurrentSelection == NULL );
219                 GetShell().SetCurNumRule( aSetRule, bCreateList );
220             }
221             // wenn der Dialog mit OK verlassen wurde, aber nichts ausgewaehlt
222             // wurde dann muss die Numerierung zumindest eingeschaltet werden,
223             // wenn sie das noch nicht ist
224             else if ( pNumRuleAtCurrentSelection == NULL
225                       && SFX_ITEM_SET == aSet.GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ) )
226             {
227                 rReq.AppendItem( *pItem );
228                 rReq.Done();
229                 SvxNumRule* pSetRule = ( (SvxNumBulletItem*) pItem )->GetNumRule();
230                 SwNumRule aSetRule(
231                     GetShell().GetUniqueNumRuleName(),
232                     numfunc::GetDefaultPositionAndSpaceMode() );
233                 aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc() );
234                 aSetRule.SetAutoRule( sal_True );
235                 // start new list
236                 GetShell().SetCurNumRule( aSetRule, true );
237             }
238         }
239         else if ( RET_USER == nRet )
240             GetShell().DelNumRules();
241 
242         delete pDlg;
243     }
244         break;
245 
246     default:
247         ASSERT( sal_False, "wrong Dispatcher" );
248         return;
249     }
250 }
251 
252 
ExecSetNumber(SfxRequest & rReq)253 void SwTextShell::ExecSetNumber(SfxRequest &rReq)
254 {
255     const sal_uInt16 nSlot = rReq.GetSlot();
256     switch ( nSlot )
257     {
258     case FN_SVX_SET_NUMBER:
259     case FN_SVX_SET_BULLET:
260         {
261             SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, nSlot, sal_False );
262             if ( pItem != NULL )
263             {
264                 const sal_uInt16 nChoosenItemIdx = pItem->GetValue();
265                 if ( nChoosenItemIdx == DEFAULT_NONE )
266                 {
267                     GetShell().DelNumRules();
268                 }
269                 else
270                 {
271                     svx::sidebar::NBOTypeMgrBase* pNBOTypeMgr =
272                         nSlot == FN_SVX_SET_NUMBER
273                             ? svx::sidebar::NBOutlineTypeMgrFact::CreateInstance( svx::sidebar::eNBOType::NUMBERING )
274                             : svx::sidebar::NBOutlineTypeMgrFact::CreateInstance( svx::sidebar::eNBOType::MIXBULLETS );
275                     if ( pNBOTypeMgr != NULL )
276                     {
277                         const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
278                         sal_uInt16 nActNumLvl = (sal_uInt16) 0xFFFF;
279                         if ( pNumRuleAtCurrentSelection != NULL )
280                         {
281                             sal_uInt16 nLevel = GetShell().GetNumLevel();
282                             if ( nLevel < MAXLEVEL )
283                             {
284                                 nActNumLvl = 1 << nLevel;
285                             }
286                         }
287                         SwNumRule aNewNumRule(
288                             pNumRuleAtCurrentSelection != NULL ? pNumRuleAtCurrentSelection->GetName() : GetShell().GetUniqueNumRuleName(),
289                             numfunc::GetDefaultPositionAndSpaceMode() );
290                         SvxNumRule aNewSvxNumRule = pNumRuleAtCurrentSelection != NULL
291                                                         ? pNumRuleAtCurrentSelection->MakeSvxNumRule()
292                                                         : aNewNumRule.MakeSvxNumRule();
293                         // set unit attribute to NB Manager
294                         SfxItemSet aSet( GetPool(), SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL, 0 );
295                         aSet.Put( SvxNumBulletItem( aNewSvxNumRule ) );
296                         pNBOTypeMgr->SetItems( &aSet );
297                         pNBOTypeMgr->ApplyNumRule( aNewSvxNumRule, nChoosenItemIdx - 1, nActNumLvl );
298 
299                         aNewNumRule.SetSvxRule( aNewSvxNumRule, GetShell().GetDoc() );
300                         aNewNumRule.SetAutoRule( sal_True );
301                         const bool bCreateNewList = ( pNumRuleAtCurrentSelection == NULL );
302                         GetShell().SetCurNumRule( aNewNumRule, bCreateNewList );
303                     }
304                 }
305             }
306         }
307         break;
308 
309     default:
310         ASSERT( sal_False, "wrong Dispatcher" );
311         return;
312     }
313 }
314