Update ooo320-m1
[ooovba.git] / sw / source / ui / shells / txtnum.cxx
blob3bbee6762431fcc498ade45087c0e97752d48ea9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: txtnum.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #ifndef _MSGBOX_HXX //autogen
37 #include <vcl/msgbox.hxx>
38 #endif
39 #include <sfx2/request.hxx>
40 #include <svtools/eitem.hxx>
41 #include <svtools/stritem.hxx>
42 #include <svx/numitem.hxx>
43 #include <svx/brshitem.hxx>
44 #include <numrule.hxx>
46 #include "cmdid.h"
47 #include "wrtsh.hxx"
48 #include "view.hxx"
49 #include "viewopt.hxx"
50 #include "wdocsh.hxx"
51 #include "textsh.hxx"
52 #include "uiitems.hxx"
53 #include "swabstdlg.hxx"
54 #include <globals.hrc>
55 #include <sfx2/tabdlg.hxx>
57 void SwTextShell::ExecEnterNum(SfxRequest &rReq)
59 //wg. Aufzeichnung schon vor dem evtl. Shellwechsel
60 switch(rReq.GetSlot())
62 case FN_NUM_NUMBERING_ON:
64 SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , sal_False );
65 BOOL bMode = !GetShell().HasNumber(); // #i29560#
66 if ( pItem )
67 bMode = pItem->GetValue();
68 else
69 rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
71 if ( bMode != (GetShell().HasNumber()) ) // #i29560#
73 rReq.Done();
74 if( bMode )
75 GetShell().NumOn();
76 else
77 GetShell().NumOrBulletOff(); // #i29560#
80 break;
81 case FN_NUM_BULLET_ON:
83 SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , sal_False );
84 BOOL bMode = !GetShell().HasBullet(); // #i29560#
85 if ( pItem )
86 bMode = pItem->GetValue();
87 else
88 rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
90 if ( bMode != (GetShell().HasBullet()) ) // #i29560#
92 rReq.Done();
93 if( bMode )
94 GetShell().BulletOn();
95 else
96 GetShell().NumOrBulletOff(); // #i29560#
99 break;
100 case FN_NUMBER_BULLETS:
102 // --> OD 2008-02-29 #refactorlists#
103 // // per default TRUE, damit die Schleife im Dialog richtig arbeitet!
104 // BOOL bHasChild = TRUE;
105 // <--
106 SfxItemSet aSet(GetPool(),
107 SID_HTML_MODE, SID_HTML_MODE,
108 SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
109 0 );
110 SwDocShell* pDocSh = GetView().GetDocShell();
111 BOOL bHtml = 0 != PTR_CAST(SwWebDocShell, pDocSh);
112 const SwNumRule* pCurRule = GetShell().GetCurNumRule();
113 if( pCurRule )
115 SvxNumRule aRule = pCurRule->MakeSvxNumRule();
117 //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
118 for(USHORT i = 0; i < aRule.GetLevelCount(); i++)
120 SvxNumberFormat aFmt(aRule.GetLevel(i));
121 if(SVX_NUM_BITMAP == aFmt.GetNumberingType())
123 const SvxBrushItem* pBrush = aFmt.GetBrush();
124 const String* pLinkStr;
125 if(pBrush &&
126 0 != (pLinkStr = pBrush->GetGraphicLink()) &&
127 pLinkStr->Len())
128 aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
129 aRule.SetLevel(i, aFmt, aRule.Get(i) != 0);
132 if(bHtml)
133 aRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, FALSE);
135 aSet.Put(SvxNumBulletItem(aRule));
136 // --> OD 2008-02-29 #refactorlists# - removed <bHasChild>
137 ASSERT( GetShell().GetNumLevel() < MAXLEVEL,
138 "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect -> please inform OD." );
139 USHORT nLevel = GetShell().GetNumLevel();
140 // <--
141 if( nLevel < MAXLEVEL )
143 nLevel = 1<<nLevel;
144 aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ));
147 else
149 // --> OD 2008-02-11 #newlistlevelattrs#
150 SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
151 // --> OD 2008-06-06 #i89178#
152 numfunc::GetDefaultPositionAndSpaceMode() );
153 // <--
154 // <--
155 SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
156 const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
158 if( bHtml || bRightToLeft )
160 for( BYTE n = 0; n < MAXLEVEL; ++n )
162 SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
163 if ( n && bHtml )
165 // 1/2" fuer HTML
166 aFmt.SetLSpace(720);
167 aFmt.SetAbsLSpace(n * 720);
169 // --> FME 2005-01-21 #i38904# Default alignment for
170 // numbering/bullet should be rtl in rtl paragraph:
171 if ( bRightToLeft )
173 aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
175 // <--
176 aSvxRule.SetLevel( n, aFmt, FALSE );
178 aSvxRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, FALSE);
180 aSet.Put(SvxNumBulletItem(aSvxRule));
183 aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET,FALSE ));
185 // vor dem Dialog wird der HtmlMode an der DocShell versenkt
186 pDocSh->PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(pDocSh)));
188 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
189 DBG_ASSERT(pFact, "Dialogdiet fail!");
190 SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_SVXTEST_NUM_BULLET,
191 GetView().GetWindow(), &aSet, GetShell());
192 DBG_ASSERT(pDlg, "Dialogdiet fail!");
193 USHORT nRet = pDlg->Execute();
194 const SfxPoolItem* pItem;
195 if( RET_OK == nRet )
197 if( SFX_ITEM_SET == pDlg->GetOutputItemSet()->GetItemState( SID_ATTR_NUMBERING_RULE, FALSE, &pItem ))
199 rReq.AppendItem(*pItem);
200 rReq.Done();
201 SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
202 pSetRule->UnLinkGraphics();
203 // --> OD 2008-02-11 #newlistlevelattrs#
204 SwNumRule aSetRule( pCurRule
205 ? pCurRule->GetName()
206 : GetShell().GetUniqueNumRuleName(),
207 // --> OD 2008-06-06 #i89178#
208 numfunc::GetDefaultPositionAndSpaceMode() );
209 // <--
210 // <--
211 aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc());
212 aSetRule.SetAutoRule( TRUE );
213 // --> OD 2008-03-17 #refactorlists#
214 // No start of new list, if an existing list style is edited.
215 // Otherwise start a new list.
216 const bool bCreateList = (pCurRule == 0);
217 GetShell().SetCurNumRule( aSetRule, bCreateList );
218 // <--
220 // wenn der Dialog mit OK verlassen wurde, aber nichts ausgewaehlt
221 // wurde dann muss die Numerierung zumindest eingeschaltet werden,
222 // wenn sie das noch nicht ist
223 else if( !pCurRule && SFX_ITEM_SET == aSet.GetItemState( SID_ATTR_NUMBERING_RULE, FALSE, &pItem ))
225 rReq.AppendItem( *pItem );
226 rReq.Done();
227 SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
228 // --> OD 2008-02-11 #newlistlevelattrs#
229 SwNumRule aSetRule( GetShell().GetUniqueNumRuleName(),
230 // --> OD 2008-06-06 #i89178#
231 numfunc::GetDefaultPositionAndSpaceMode() );
232 // <--
233 // <--
234 aSetRule.SetSvxRule(*pSetRule, GetShell().GetDoc());
235 aSetRule.SetAutoRule( TRUE );
236 // --> OD 2008-03-17 #refactorlists#
237 // start new list
238 GetShell().SetCurNumRule( aSetRule, true );
239 // <--
242 else if(RET_USER == nRet)
243 GetShell().DelNumRules();
245 delete pDlg;
247 break;
248 default:
249 ASSERT(FALSE, falscher Dispatcher);
250 return;