xref: /trunk/main/sw/source/ui/shells/txtnum.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <hintids.hxx>
33 #ifndef _MSGBOX_HXX //autogen
34 #include <vcl/msgbox.hxx>
35 #endif
36 #include <sfx2/request.hxx>
37 #include <svl/eitem.hxx>
38 #include <svl/stritem.hxx>
39 #include <editeng/numitem.hxx>
40 #include <editeng/brshitem.hxx>
41 #include <numrule.hxx>
42 
43 #include "cmdid.h"
44 #include "wrtsh.hxx"
45 #include "view.hxx"
46 #include "viewopt.hxx"
47 #include "wdocsh.hxx"
48 #include "textsh.hxx"
49 #include "uiitems.hxx"
50 #include "swabstdlg.hxx"
51 #include <globals.hrc>
52 #include <sfx2/tabdlg.hxx>
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     {
99         // --> OD 2008-02-29 #refactorlists#
100 //        // per default sal_True, damit die Schleife im Dialog richtig arbeitet!
101 //        sal_Bool bHasChild = sal_True;
102         // <--
103         SfxItemSet aSet(GetPool(),
104                 SID_HTML_MODE, SID_HTML_MODE,
105                 SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
106                 0 );
107         SwDocShell* pDocSh = GetView().GetDocShell();
108         sal_Bool bHtml = 0 != PTR_CAST(SwWebDocShell, pDocSh);
109         const SwNumRule* pCurRule = GetShell().GetCurNumRule();
110         if( pCurRule )
111         {
112             SvxNumRule aRule = pCurRule->MakeSvxNumRule();
113 
114             //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
115             for(sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++)
116             {
117                 SvxNumberFormat aFmt(aRule.GetLevel(i));
118                 if(SVX_NUM_BITMAP == aFmt.GetNumberingType())
119                 {
120                     const SvxBrushItem* pBrush = aFmt.GetBrush();
121                     const String* pLinkStr;
122                     if(pBrush &&
123                         0 != (pLinkStr = pBrush->GetGraphicLink()) &&
124                             pLinkStr->Len())
125                         aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
126                     aRule.SetLevel(i, aFmt, aRule.Get(i) != 0);
127                 }
128             }
129             if(bHtml)
130                 aRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
131 
132             aSet.Put(SvxNumBulletItem(aRule));
133             // --> OD 2008-02-29 #refactorlists# - removed <bHasChild>
134             ASSERT( GetShell().GetNumLevel() < MAXLEVEL,
135                     "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect -> please inform OD." );
136             sal_uInt16 nLevel = GetShell().GetNumLevel();
137             // <--
138             if( nLevel < MAXLEVEL )
139             {
140                 nLevel = 1<<nLevel;
141                 aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ));
142             }
143         }
144         else
145         {
146             // --> OD 2008-02-11 #newlistlevelattrs#
147             SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
148                              // --> OD 2008-06-06 #i89178#
149                              numfunc::GetDefaultPositionAndSpaceMode() );
150                              // <--
151             // <--
152             SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
153             const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
154 
155             if( bHtml || bRightToLeft )
156             {
157                 for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
158                 {
159                     SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
160                     if ( n && bHtml )
161                     {
162                         // 1/2" fuer HTML
163                         aFmt.SetLSpace(720);
164                         aFmt.SetAbsLSpace(n * 720);
165                     }
166                     // --> FME 2005-01-21 #i38904#  Default alignment for
167                     // numbering/bullet should be rtl in rtl paragraph:
168                     if ( bRightToLeft )
169                     {
170                         aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
171                     }
172                     // <--
173                     aSvxRule.SetLevel( n, aFmt, sal_False );
174                 }
175                 aSvxRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
176             }
177             aSet.Put(SvxNumBulletItem(aSvxRule));
178         }
179 
180         aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET,sal_False ));
181 
182         // vor dem Dialog wird der HtmlMode an der DocShell versenkt
183         pDocSh->PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(pDocSh)));
184 
185         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
186         DBG_ASSERT(pFact, "Dialogdiet fail!");
187         SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_SVXTEST_NUM_BULLET,
188                                                         GetView().GetWindow(), &aSet, GetShell());
189         DBG_ASSERT(pDlg, "Dialogdiet fail!");
190         sal_uInt16 nRet = pDlg->Execute();
191         const SfxPoolItem* pItem;
192         if( RET_OK == nRet )
193         {
194             if( SFX_ITEM_SET == pDlg->GetOutputItemSet()->GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ))
195             {
196                 rReq.AppendItem(*pItem);
197                 rReq.Done();
198                 SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
199                 pSetRule->UnLinkGraphics();
200                 // --> OD 2008-02-11 #newlistlevelattrs#
201                 SwNumRule aSetRule( pCurRule
202                                         ? pCurRule->GetName()
203                                         : GetShell().GetUniqueNumRuleName(),
204                                     // --> OD 2008-06-06 #i89178#
205                                     numfunc::GetDefaultPositionAndSpaceMode() );
206                                     // <--
207                 // <--
208                 aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc());
209                 aSetRule.SetAutoRule( sal_True );
210                 // --> OD 2008-03-17 #refactorlists#
211                 // No start of new list, if an existing list style is edited.
212                 // Otherwise start a new list.
213                 const bool bCreateList = (pCurRule == 0);
214                 GetShell().SetCurNumRule( aSetRule, bCreateList );
215                 // <--
216             }
217             // wenn der Dialog mit OK verlassen wurde, aber nichts ausgewaehlt
218             // wurde dann muss die Numerierung zumindest eingeschaltet werden,
219             // wenn sie das noch nicht ist
220             else if( !pCurRule && SFX_ITEM_SET == aSet.GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ))
221             {
222                 rReq.AppendItem( *pItem );
223                 rReq.Done();
224                 SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
225                 // --> OD 2008-02-11 #newlistlevelattrs#
226                 SwNumRule aSetRule( GetShell().GetUniqueNumRuleName(),
227                                     // --> OD 2008-06-06 #i89178#
228                                     numfunc::GetDefaultPositionAndSpaceMode() );
229                                     // <--
230                 // <--
231                 aSetRule.SetSvxRule(*pSetRule, GetShell().GetDoc());
232                 aSetRule.SetAutoRule( sal_True );
233                 // --> OD 2008-03-17 #refactorlists#
234                 // start new list
235                 GetShell().SetCurNumRule( aSetRule, true );
236                 // <--
237             }
238         }
239         else if(RET_USER == nRet)
240             GetShell().DelNumRules();
241 
242         delete pDlg;
243     }
244     break;
245     default:
246         ASSERT(sal_False,  falscher Dispatcher);
247         return;
248     }
249 }
250 
251 
252