summaryrefslogtreecommitdiff
path: root/sw/source/core/uibase/shells/txtnum.cxx
blob: bffbfc2c3583f0e7bbb63eb6d1210eb7f3e2ad72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <hintids.hxx>
#include <vcl/msgbox.hxx>
#include <sfx2/request.hxx>
#include <svl/eitem.hxx>
#include <svl/stritem.hxx>
#include <editeng/numitem.hxx>
#include <editeng/brushitem.hxx>
#include <numrule.hxx>

#include "cmdid.h"
#include "wrtsh.hxx"
#include "view.hxx"
#include "viewopt.hxx"
#include "wdocsh.hxx"
#include "textsh.hxx"
#include "uiitems.hxx"
#include "swabstdlg.hxx"
#include <globals.hrc>
#include <sfx2/tabdlg.hxx>
#include <svx/nbdtmg.hxx>
#include <svx/nbdtmgfact.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/bindings.hxx>
using namespace svx::sidebar;

void SwTextShell::ExecEnterNum(SfxRequest &rReq)
{
    //Because the record before any shell exchange.
    switch(rReq.GetSlot())
    {
    case FN_NUM_NUMBERING_ON:
    {
        GetShell().StartAllAction();
        SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , false );
        sal_Bool bMode = !GetShell().SelectionHasNumber(); // #i29560#
        if ( pItem )
            bMode = pItem->GetValue();
        else
            rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );

        if ( bMode != (GetShell().SelectionHasNumber()) ) // #i29560#
        {
            rReq.Done();
            if( bMode )
                GetShell().NumOn();
            else
                GetShell().NumOrBulletOff(); // #i29560#
        }
        sal_Bool bNewResult = GetShell().SelectionHasNumber();
        if (bNewResult!=bMode) {
            SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
            SfxBoolItem aItem(FN_NUM_NUMBERING_ON,!bNewResult);
            rBindings.SetState(aItem);
            SfxBoolItem aNewItem(FN_NUM_NUMBERING_ON,bNewResult);
            rBindings.SetState(aNewItem);
        }
        GetShell().EndAllAction();
    }
    break;
    case FN_NUM_BULLET_ON:
    {
        GetShell().StartAllAction();
        SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , false );
        sal_Bool bMode = !GetShell().SelectionHasBullet(); // #i29560#
        if ( pItem )
            bMode = pItem->GetValue();
        else
            rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );

        if ( bMode != (GetShell().SelectionHasBullet()) ) // #i29560#
        {
            rReq.Done();
            if( bMode )
                GetShell().BulletOn();
            else
                GetShell().NumOrBulletOff(); // #i29560#
        }
        sal_Bool bNewResult = GetShell().SelectionHasBullet();
        if (bNewResult!=bMode) {
            SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
            SfxBoolItem aItem(FN_NUM_BULLET_ON,!bNewResult);
            rBindings.SetState(aItem);
            SfxBoolItem aNewItem(FN_NUM_BULLET_ON,bNewResult);
            rBindings.SetState(aNewItem);
        }
        GetShell().EndAllAction();
    }
    break;
    case FN_NUMBER_BULLETS:
    case SID_OUTLINE_BULLET:
    {
        SfxItemSet aSet(GetPool(),
                SID_HTML_MODE, SID_HTML_MODE,
                SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
                0 );
        SwDocShell* pDocSh = GetView().GetDocShell();
        bool bHtml = 0 != PTR_CAST(SwWebDocShell, pDocSh);
        const SwNumRule* pCurRule = GetShell().GetCurNumRule();
        if( pCurRule )
        {
            SvxNumRule aRule = pCurRule->MakeSvxNumRule();

            //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
            for(sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++)
            {
                SvxNumberFormat aFmt(aRule.GetLevel(i));
                if(SVX_NUM_BITMAP == aFmt.GetNumberingType())
                {
                    const SvxBrushItem* pBrush = aFmt.GetBrush();
                    if(pBrush && !pBrush->GetGraphicLink().isEmpty())
                        aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
                    aRule.SetLevel(i, aFmt, aRule.Get(i) != 0);
                }
            }
            if(bHtml)
                aRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, false);

            aSet.Put(SvxNumBulletItem(aRule));
            OSL_ENSURE( GetShell().GetNumLevel() < MAXLEVEL,
                    "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect -> please inform OD." );
            sal_uInt16 nLevel = GetShell().GetNumLevel();
            if( nLevel < MAXLEVEL )
            {
                nLevel = 1<<nLevel;
                aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ));
            }
        }
        else
        {
            SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
                             // #i89178#
                             numfunc::GetDefaultPositionAndSpaceMode() );
            SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
            const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );

            if( bHtml || bRightToLeft )
            {
                for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
                {
                    SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
                    if ( n && bHtml )
                    {
                        // 1/2" for HTML
                        aFmt.SetLSpace(720);
                        aFmt.SetAbsLSpace(n * 720);
                    }
                    // #i38904#  Default alignment for
                    // numbering/bullet should be rtl in rtl paragraph:
                    if ( bRightToLeft )
                    {
                        aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
                    }
                    aSvxRule.SetLevel( n, aFmt, false );
                }
                aSvxRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, false);
            }
            aSet.Put(SvxNumBulletItem(aSvxRule));
        }

        aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET,false ));

        // Before the dialogue of the HTML mode will be dropped at the Docshell.
        pDocSh->PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(pDocSh)));

        SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
        OSL_ENSURE(pFact, "Dialogdiet fail!");
        SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_SVXTEST_NUM_BULLET,
                                                        GetView().GetWindow(), &aSet, GetShell());
        OSL_ENSURE(pDlg, "Dialogdiet fail!");
        sal_uInt16 nRet = pDlg->Execute();
        const SfxPoolItem* pItem;
        if( RET_OK == nRet )
        {
            if( SFX_ITEM_SET == pDlg->GetOutputItemSet()->GetItemState( SID_ATTR_NUMBERING_RULE, false, &pItem ))
            {
                rReq.AppendItem(*pItem);
                rReq.Done();
                SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
                pSetRule->UnLinkGraphics();
                SwNumRule aSetRule( pCurRule
                                        ? pCurRule->GetName()
                                        : GetShell().GetUniqueNumRuleName(),
                                    // #i89178#
                                    numfunc::GetDefaultPositionAndSpaceMode() );
                aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc());
                aSetRule.SetAutoRule( sal_True );
                // No start of new list, if an existing list style is edited.
                // Otherwise start a new list.
                const bool bCreateList = (pCurRule == 0);
                GetShell().SetCurNumRule( aSetRule, bCreateList );
            }
            // If the Dialog was leaved with OK but nothing was chosen then the
            // numbering must be at least activated, if it is not already.
            else if( !pCurRule && SFX_ITEM_SET == aSet.GetItemState( SID_ATTR_NUMBERING_RULE, false, &pItem ))
            {
                rReq.AppendItem( *pItem );
                rReq.Done();
                SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
                SwNumRule aSetRule( GetShell().GetUniqueNumRuleName(),
                                    // #i89178#
                                    numfunc::GetDefaultPositionAndSpaceMode() );
                aSetRule.SetSvxRule(*pSetRule, GetShell().GetDoc());
                aSetRule.SetAutoRule( sal_True );
                // start new list
                GetShell().SetCurNumRule( aSetRule, true );
            }
        }
        else if(RET_USER == nRet)
            GetShell().DelNumRules();

        delete pDlg;
    }
    break;
    default:
        OSL_FAIL("wrong dispatcher");
        return;
    }
}

void SwTextShell::ExecSetNumber(SfxRequest &rReq)
{
    SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
                         // #i89178#
                         numfunc::GetDefaultPositionAndSpaceMode() );

    SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
    const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );

    if( bRightToLeft )
    {
        for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
        {
            SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
           /* if ( n && bHtml )
            {
                // 1/2" for HTML
                aFmt.SetLSpace(720);
                aFmt.SetAbsLSpace(n * 720);
            }*/
            // #i38904#  Default alignment for
            // numbering/bullet should be rtl in rtl paragraph:
            if ( bRightToLeft )
            {
                aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
            }
            aSvxRule.SetLevel( n, aFmt, false );
        }
        aSvxRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, false);
    }

    const SwNumRule* pCurRule = GetShell().GetCurNumRule();
    sal_uInt16      nActNumLvl = (sal_uInt16)0xFFFF;
    if( pCurRule )
    {
        sal_uInt16 nLevel = GetShell().GetNumLevel();
        if( nLevel < MAXLEVEL )
        {
            nActNumLvl = 1<<nLevel;
        }

        aSvxRule = pCurRule->MakeSvxNumRule();

        //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
        for(sal_uInt16 i = 0; i < aSvxRule.GetLevelCount(); i++)
        {
            SvxNumberFormat aFmt(aSvxRule.GetLevel(i));
            if(SVX_NUM_BITMAP == aFmt.GetNumberingType())
            {
                const SvxBrushItem* pBrush = aFmt.GetBrush();
                if( pBrush && !pBrush->GetGraphicLink().isEmpty() )
                    aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
                aSvxRule.SetLevel(i, aFmt, aSvxRule.Get(i) != 0);
            }
        }
    }

    switch(rReq.GetSlot())
    {
    case FN_SVX_SET_NUMBER:
        {
            SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, FN_SVX_SET_NUMBER , false );
            if (pItem)
            {
                sal_uInt16 nIdx = pItem->GetValue();
                if (nIdx==DEFAULT_NONE) {
                    GetShell().DelNumRules();
                    break;
                }
                --nIdx;

                NBOTypeMgrBase* pNumbering = NBOutlineTypeMgrFact::CreateInstance(eNBOType::NUMBERING);
                if ( pNumbering )
                {
                    SwNumRule aTmpRule( GetShell().GetUniqueNumRuleName(),
                         numfunc::GetDefaultPositionAndSpaceMode() );

                    SvxNumRule aTempRule = aTmpRule.MakeSvxNumRule();
                    // set unit attribute to NB Manager
                    SfxItemSet aSet(GetPool(),
                            SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
                            0 );
                    aSet.Put(SvxNumBulletItem(aTempRule));
                    pNumbering->SetItems(&aSet);
                    pNumbering->ApplyNumRule(aTempRule,nIdx,nActNumLvl);

                    sal_uInt16 nMask = 1;
                    for(sal_uInt16 i = 0; i < aSvxRule.GetLevelCount(); i++)
                    {
                        if(nActNumLvl & nMask)
                        {
                            SvxNumberFormat aFmt(aTempRule.GetLevel(i));
                            aSvxRule.SetLevel(i, aFmt);
                        }
                        nMask <<= 1 ;
                    }

                    aSvxRule.UnLinkGraphics();
                    SwNumRule aSetRule( pCurRule
                                            ? pCurRule->GetName()
                                            : GetShell().GetUniqueNumRuleName(),
                                        numfunc::GetDefaultPositionAndSpaceMode() );
                    aSetRule.SetSvxRule( aSvxRule, GetShell().GetDoc());

                    aSetRule.SetAutoRule( sal_True );
                    const bool bCreateList = (pCurRule == 0);
                    GetShell().SetCurNumRule( aSetRule, bCreateList );
                }
                //End
            }
            break;
        }
    case FN_SVX_SET_BULLET:
        {
            SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, FN_SVX_SET_BULLET , false );
            if (pItem)
            {
                sal_uInt16 nIdx = pItem->GetValue();
                if (nIdx==DEFAULT_NONE) {
                    GetShell().DelNumRules();
                    break;
                }
                nIdx--;

                NBOTypeMgrBase* pBullets = NBOutlineTypeMgrFact::CreateInstance(eNBOType::MIXBULLETS);
                if ( pBullets )
                {
                    SwNumRule aTmpRule( GetShell().GetUniqueNumRuleName(),
                         numfunc::GetDefaultPositionAndSpaceMode() );

                    SvxNumRule aTempRule = aTmpRule.MakeSvxNumRule();
                    // set unit attribute to NB Manager
                    SfxItemSet aSet(GetPool(),
                            SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
                            0 );
                    aSet.Put(SvxNumBulletItem(aTempRule));
                    pBullets->SetItems(&aSet);

                    //SvxNumRule aTempRule( 0, 10, false );
                    pBullets->ApplyNumRule(aTempRule,nIdx,nActNumLvl);
                    sal_uInt16 nMask = 1;
                    for(sal_uInt16 i = 0; i < aSvxRule.GetLevelCount(); i++)
                    {
                        if(nActNumLvl & nMask)
                        {
                            SvxNumberFormat aFmt(aTempRule.GetLevel(i));
                            aSvxRule.SetLevel(i, aFmt);
                        }
                        nMask <<= 1;
                    }
                    aSvxRule.UnLinkGraphics();

                    SwNumRule aSetRule( pCurRule
                                            ? pCurRule->GetName()
                                            : GetShell().GetUniqueNumRuleName(),
                                        numfunc::GetDefaultPositionAndSpaceMode() );

                    aSetRule.SetSvxRule( aSvxRule, GetShell().GetDoc());

                    aSetRule.SetAutoRule( sal_True );
                    const bool bCreateList = (pCurRule == 0);
                    GetShell().SetCurNumRule( aSetRule, bCreateList );
                }
                //End
            }

        }
        break;
    }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */