Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
28 :
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 : #include <boost/scoped_ptr.hpp>
44 :
45 0 : void SwTextShell::ExecEnterNum(SfxRequest &rReq)
46 : {
47 : //Because the record before any shell exchange.
48 0 : switch(rReq.GetSlot())
49 : {
50 : case FN_NUM_NUMBERING_ON:
51 : {
52 0 : GetShell().StartAllAction();
53 0 : SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , false );
54 0 : bool bMode = !GetShell().SelectionHasNumber(); // #i29560#
55 0 : if ( pItem )
56 0 : bMode = pItem->GetValue();
57 : else
58 0 : rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
59 :
60 0 : if ( bMode != (GetShell().SelectionHasNumber()) ) // #i29560#
61 : {
62 0 : rReq.Done();
63 0 : if( bMode )
64 0 : GetShell().NumOn();
65 : else
66 0 : GetShell().NumOrBulletOff(); // #i29560#
67 : }
68 0 : bool bNewResult = GetShell().SelectionHasNumber();
69 0 : if (bNewResult!=bMode) {
70 0 : SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
71 0 : SfxBoolItem aItem(FN_NUM_NUMBERING_ON,!bNewResult);
72 0 : rBindings.SetState(aItem);
73 0 : SfxBoolItem aNewItem(FN_NUM_NUMBERING_ON,bNewResult);
74 0 : rBindings.SetState(aNewItem);
75 : }
76 0 : GetShell().EndAllAction();
77 : }
78 0 : break;
79 : case FN_NUM_BULLET_ON:
80 : {
81 0 : GetShell().StartAllAction();
82 0 : SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , false );
83 0 : bool bMode = !GetShell().SelectionHasBullet(); // #i29560#
84 0 : if ( pItem )
85 0 : bMode = pItem->GetValue();
86 : else
87 0 : rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
88 :
89 0 : if ( bMode != (GetShell().SelectionHasBullet()) ) // #i29560#
90 : {
91 0 : rReq.Done();
92 0 : if( bMode )
93 0 : GetShell().BulletOn();
94 : else
95 0 : GetShell().NumOrBulletOff(); // #i29560#
96 : }
97 0 : bool bNewResult = GetShell().SelectionHasBullet();
98 0 : if (bNewResult!=bMode) {
99 0 : SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
100 0 : SfxBoolItem aItem(FN_NUM_BULLET_ON,!bNewResult);
101 0 : rBindings.SetState(aItem);
102 0 : SfxBoolItem aNewItem(FN_NUM_BULLET_ON,bNewResult);
103 0 : rBindings.SetState(aNewItem);
104 : }
105 0 : GetShell().EndAllAction();
106 : }
107 0 : break;
108 :
109 : case FN_NUMBER_BULLETS:
110 : case SID_OUTLINE_BULLET:
111 : {
112 0 : SfxItemSet aSet( GetPool(),
113 : SID_HTML_MODE, SID_HTML_MODE,
114 : SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
115 0 : 0 );
116 0 : SwDocShell* pDocSh = GetView().GetDocShell();
117 0 : const bool bHtml = 0 != PTR_CAST( SwWebDocShell, pDocSh );
118 0 : const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
119 0 : if ( pNumRuleAtCurrentSelection != NULL )
120 : {
121 0 : SvxNumRule aRule = pNumRuleAtCurrentSelection->MakeSvxNumRule();
122 :
123 : //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
124 0 : for ( sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++ )
125 : {
126 0 : SvxNumberFormat aFmt( aRule.GetLevel( i ) );
127 0 : if ( SVX_NUM_BITMAP == aFmt.GetNumberingType() )
128 : {
129 0 : const SvxBrushItem* pBrush = aFmt.GetBrush();
130 0 : if(pBrush && !pBrush->GetGraphicLink().isEmpty())
131 0 : aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
132 0 : aRule.SetLevel(i, aFmt, aRule.Get(i) != 0);
133 : }
134 0 : }
135 0 : if(bHtml)
136 0 : aRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, false);
137 :
138 0 : aSet.Put(SvxNumBulletItem(aRule));
139 : OSL_ENSURE( GetShell().GetNumLevel() < MAXLEVEL,
140 : "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect -> please inform OD." );
141 0 : sal_uInt16 nLevel = GetShell().GetNumLevel();
142 0 : if( nLevel < MAXLEVEL )
143 : {
144 0 : nLevel = 1 << nLevel;
145 0 : aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
146 0 : }
147 : }
148 : else
149 : {
150 0 : SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
151 : // #i89178#
152 0 : numfunc::GetDefaultPositionAndSpaceMode() );
153 0 : SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
154 0 : const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
155 :
156 0 : if ( bHtml || bRightToLeft )
157 : {
158 0 : for ( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
159 : {
160 0 : SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
161 0 : if ( n && bHtml )
162 : {
163 : // 1/2" for HTML
164 0 : aFmt.SetLSpace(720);
165 0 : aFmt.SetAbsLSpace(n * 720);
166 : }
167 : // #i38904# Default alignment for
168 : // numbering/bullet should be rtl in rtl paragraph:
169 0 : if ( bRightToLeft )
170 : {
171 0 : aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
172 : }
173 0 : aSvxRule.SetLevel( n, aFmt, false );
174 0 : }
175 0 : aSvxRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, false);
176 : }
177 0 : aSet.Put( SvxNumBulletItem( aSvxRule ) );
178 : }
179 :
180 0 : aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET,false ));
181 :
182 : // Before the dialogue of the HTML mode will be dropped at the Docshell.
183 0 : pDocSh->PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(pDocSh)));
184 :
185 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
186 : OSL_ENSURE(pFact, "Dialog creation failed!");
187 : boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateSwTabDialog( DLG_SVXTEST_NUM_BULLET,
188 0 : GetView().GetWindow(), &aSet, GetShell()));
189 : OSL_ENSURE(pDlg, "Dialog creation failed!");
190 0 : const short nRet = pDlg->Execute();
191 : const SfxPoolItem* pItem;
192 0 : if ( RET_OK == nRet )
193 : {
194 0 : if( SfxItemState::SET == pDlg->GetOutputItemSet()->GetItemState( SID_ATTR_NUMBERING_RULE, false, &pItem ))
195 : {
196 0 : rReq.AppendItem( *pItem );
197 0 : rReq.Done();
198 0 : SvxNumRule* pSetRule = ( (SvxNumBulletItem*) pItem )->GetNumRule();
199 0 : pSetRule->UnLinkGraphics();
200 : SwNumRule aSetRule( pNumRuleAtCurrentSelection != NULL
201 : ? pNumRuleAtCurrentSelection->GetName()
202 0 : : GetShell().GetUniqueNumRuleName(),
203 0 : numfunc::GetDefaultPositionAndSpaceMode() );
204 0 : aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc() );
205 0 : aSetRule.SetAutoRule( true );
206 : // No start of new list, if an existing list style is edited.
207 : // Otherwise start a new list.
208 0 : const bool bCreateList = ( pNumRuleAtCurrentSelection == NULL );
209 0 : GetShell().SetCurNumRule( aSetRule, bCreateList );
210 : }
211 : // If the Dialog was leaved with OK but nothing was chosen then the
212 : // numbering must be at least activated, if it is not already.
213 0 : else if ( pNumRuleAtCurrentSelection == NULL
214 0 : && SfxItemState::SET == aSet.GetItemState( SID_ATTR_NUMBERING_RULE, false, &pItem ) )
215 : {
216 0 : rReq.AppendItem( *pItem );
217 0 : rReq.Done();
218 0 : SvxNumRule* pSetRule = ( (SvxNumBulletItem*) pItem )->GetNumRule();
219 : SwNumRule aSetRule(
220 0 : GetShell().GetUniqueNumRuleName(),
221 0 : numfunc::GetDefaultPositionAndSpaceMode() );
222 0 : aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc() );
223 0 : aSetRule.SetAutoRule( true );
224 : // start new list
225 0 : GetShell().SetCurNumRule( aSetRule, true );
226 : }
227 : }
228 0 : else if ( RET_USER == nRet )
229 0 : GetShell().DelNumRules();
230 : }
231 0 : break;
232 :
233 : default:
234 : OSL_FAIL("wrong dispatcher");
235 0 : return;
236 : }
237 : }
238 :
239 :
240 0 : void SwTextShell::ExecSetNumber(SfxRequest &rReq)
241 : {
242 0 : const sal_uInt16 nSlot = rReq.GetSlot();
243 0 : switch ( nSlot )
244 : {
245 : case FN_SVX_SET_NUMBER:
246 : case FN_SVX_SET_BULLET:
247 : {
248 0 : SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, nSlot, false );
249 0 : if ( pItem != NULL )
250 : {
251 0 : const sal_uInt16 nChoosenItemIdx = pItem->GetValue();
252 0 : if ( nChoosenItemIdx == DEFAULT_NONE )
253 : {
254 0 : GetShell().DelNumRules();
255 : }
256 : else
257 : {
258 : svx::sidebar::NBOTypeMgrBase* pNBOTypeMgr =
259 : nSlot == FN_SVX_SET_NUMBER
260 : ? svx::sidebar::NBOutlineTypeMgrFact::CreateInstance( svx::sidebar::eNBOType::NUMBERING )
261 0 : : svx::sidebar::NBOutlineTypeMgrFact::CreateInstance( svx::sidebar::eNBOType::MIXBULLETS );
262 0 : if ( pNBOTypeMgr != NULL )
263 : {
264 0 : const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
265 0 : sal_uInt16 nActNumLvl = USHRT_MAX;
266 0 : if ( pNumRuleAtCurrentSelection != NULL )
267 : {
268 0 : const sal_uInt16 nLevel = GetShell().GetNumLevel();
269 0 : if ( nLevel < MAXLEVEL )
270 : {
271 0 : nActNumLvl = 1 << nLevel;
272 : }
273 : }
274 : SwNumRule aNewNumRule(
275 0 : pNumRuleAtCurrentSelection != NULL ? pNumRuleAtCurrentSelection->GetName() : GetShell().GetUniqueNumRuleName(),
276 0 : numfunc::GetDefaultPositionAndSpaceMode() );
277 : SvxNumRule aNewSvxNumRule = pNumRuleAtCurrentSelection != NULL
278 : ? pNumRuleAtCurrentSelection->MakeSvxNumRule()
279 0 : : aNewNumRule.MakeSvxNumRule();
280 : // set unit attribute to NB Manager
281 0 : SfxItemSet aSet( GetPool(), SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL, 0 );
282 0 : aSet.Put( SvxNumBulletItem( aNewSvxNumRule ) );
283 0 : pNBOTypeMgr->SetItems( &aSet );
284 0 : pNBOTypeMgr->ApplyNumRule( aNewSvxNumRule, nChoosenItemIdx - 1, nActNumLvl );
285 :
286 0 : aNewNumRule.SetSvxRule( aNewSvxNumRule, GetShell().GetDoc() );
287 0 : aNewNumRule.SetAutoRule( true );
288 0 : const bool bCreateNewList = ( pNumRuleAtCurrentSelection == NULL );
289 0 : GetShell().SetCurNumRule( aNewNumRule, bCreateNewList );
290 : }
291 : }
292 : }
293 : }
294 0 : break;
295 :
296 : default:
297 : OSL_ENSURE(false, "wrong Dispatcher");
298 0 : return;
299 : }
300 270 : }
301 :
302 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|